update scripts/salt_schema.sql
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2025-05-14 14:13:36 +02:00
parent 0242de8854
commit ca1e8a59b8

View File

@ -2,8 +2,8 @@
-- PostgreSQL database dump -- PostgreSQL database dump
-- --
-- Dumped from database version 13.10 (Debian 13.10-1.pgdg110+1) -- Dumped from database version 15.12 (Debian 15.12-0+deb12u2)
-- Dumped by pg_dump version 13.10 (Debian 13.10-1.pgdg110+1) -- Dumped by pg_dump version 15.12 (Debian 15.12-0+deb12u2)
SET statement_timeout = 0; SET statement_timeout = 0;
SET lock_timeout = 0; SET lock_timeout = 0;
@ -24,7 +24,7 @@ CREATE EXTENSION IF NOT EXISTS btree_gin WITH SCHEMA public;
-- --
-- Name: EXTENSION btree_gin; Type: COMMENT; Schema: -; Owner: -- Name: EXTENSION btree_gin; Type: COMMENT; Schema: -; Owner:
-- --
COMMENT ON EXTENSION btree_gin IS 'support for indexing common datatypes in GIN'; COMMENT ON EXTENSION btree_gin IS 'support for indexing common datatypes in GIN';
@ -38,30 +38,44 @@ CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public;
-- --
-- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: -- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner:
-- --
COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams'; COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams';
-- --
-- Name: archive_after_n_days(integer); Type: FUNCTION; Schema: public; Owner: paul -- Name: archive_after_n_days(integer); Type: PROCEDURE; Schema: public; Owner: salt
-- --
CREATE FUNCTION public.archive_after_n_days(days integer) RETURNS void CREATE PROCEDURE public.archive_after_n_days(IN days integer)
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN
INSERT INTO salt_events_archive (id, tag, data, alter_time, master_id) (SELECT id, tag, data, alter_time, master_id FROM salt_events WHERE alter_time < current_date - format('%s day', days)::interval); INSERT INTO salt_events_archive (id, tag, data, alter_time, master_id) (SELECT id, tag, data, alter_time, master_id FROM salt_events WHERE alter_time < current_date - format('%s day', days)::interval);
DELETE FROM salt_events WHERE alter_time < current_date - format('%s day', days)::interval; DELETE FROM salt_events WHERE alter_time < current_date - format('%s day', days)::interval;
END; END;$$;
$$;
ALTER FUNCTION public.archive_after_n_days(days integer) OWNER TO paul; ALTER PROCEDURE public.archive_after_n_days(IN days integer) OWNER TO salt;
-- --
-- Name: delete_inc(text); Type: FUNCTION; Schema: public; Owner: paul -- Name: cleanup(integer); Type: PROCEDURE; Schema: public; Owner: salt
--
CREATE PROCEDURE public.cleanup(IN days integer)
LANGUAGE plpgsql
AS $$
BEGIN
EXECUTE 'call archive_after_n_days('||days||');';
EXECUTE 'call drop_archive_after_n_days('||days||')';
END;$$;
ALTER PROCEDURE public.cleanup(IN days integer) OWNER TO salt;
--
-- Name: delete_inc(text); Type: FUNCTION; Schema: public; Owner: salt
-- --
CREATE FUNCTION public.delete_inc(sdate text) RETURNS void CREATE FUNCTION public.delete_inc(sdate text) RETURNS void
@ -73,22 +87,21 @@ END;
$$; $$;
ALTER FUNCTION public.delete_inc(sdate text) OWNER TO paul; ALTER FUNCTION public.delete_inc(sdate text) OWNER TO salt;
-- --
-- Name: drop_archive_after_n_days(integer); Type: FUNCTION; Schema: public; Owner: paul -- Name: drop_archive_after_n_days(integer); Type: PROCEDURE; Schema: public; Owner: salt
-- --
CREATE FUNCTION public.drop_archive_after_n_days(days integer) RETURNS void CREATE PROCEDURE public.drop_archive_after_n_days(IN days integer)
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
BEGIN BEGIN
DELETE FROM salt_events_archive WHERE alter_time <= current_date - format('%s day', days)::interval; DELETE FROM salt_events_archive WHERE alter_time <= current_date - format('%s day', days)::interval;
END; END;$$;
$$;
ALTER FUNCTION public.drop_archive_after_n_days(days integer) OWNER TO paul; ALTER PROCEDURE public.drop_archive_after_n_days(IN days integer) OWNER TO salt;
-- --
-- Name: seq_salt_events_id; Type: SEQUENCE; Schema: public; Owner: salt -- Name: seq_salt_events_id; Type: SEQUENCE; Schema: public; Owner: salt
@ -147,7 +160,7 @@ CREATE VIEW public.highstate AS
se.data, se.data,
se.alter_time se.alter_time
FROM public.salt_events se FROM public.salt_events se
WHERE (jsonb_extract_path_text(se.data, VARIADIC ARRAY['fun'::text]) = 'state.highstate'::text) WHERE ((jsonb_extract_path_text(se.data, VARIADIC ARRAY['fun'::text]) = 'state.highstate'::text) OR (jsonb_extract_path_text(se.data, VARIADIC ARRAY['fun'::text]) = 'state.apply'::text))
ORDER BY se.id DESC ORDER BY se.id DESC
LIMIT 100; LIMIT 100;
@ -155,23 +168,24 @@ CREATE VIEW public.highstate AS
ALTER TABLE public.highstate OWNER TO salt; ALTER TABLE public.highstate OWNER TO salt;
-- --
-- Name: highstate_summary; Type: VIEW; Schema: public; Owner: salt -- Name: highstate_errors; Type: VIEW; Schema: public; Owner: salt
-- --
CREATE VIEW public.highstate_summary AS CREATE VIEW public.highstate_errors AS
SELECT se.id, SELECT se.id,
se.tag, se.tag,
se.alter_time AS "time", se.alter_time AS "time",
(se.data ->> 'id'::text) AS hostname, (se.data ->> 'id'::text) AS hostname,
split_part(dt.key, '_|-'::text, 2) AS salt_state, split_part(dt.key, '_|-'::text, 2) AS salt_state,
(dt.value ->> 'comment'::text) AS comment (dt.value ->> 'comment'::text) AS comment,
((dt.value ->> 'duration'::text))::double precision AS duration
FROM public.salt_events se, FROM public.salt_events se,
LATERAL jsonb_each((se.data -> 'return'::text)) dt(key, value) LATERAL jsonb_each((se.data -> 'return'::text)) dt(key, value)
WHERE (((se.data ->> 'fun'::text) = 'state.highstate'::text) AND ((se.data ->> 'id'::text) IS NOT NULL) AND ((se.data ->> 'success'::text) IS NOT NULL) AND (NOT ((dt.value ->> 'result'::text))::boolean) AND (jsonb_typeof((se.data -> 'return'::text)) = 'object'::text) AND (se.alter_time > (CURRENT_DATE - '1 day'::interval))) WHERE ((((se.data ->> 'fun'::text) = 'state.highstate'::text) OR ((se.data ->> 'fun'::text) = 'state.apply'::text)) AND ((se.data ->> 'id'::text) IS NOT NULL) AND ((se.data ->> 'success'::text) IS NOT NULL) AND (NOT ((dt.value ->> 'result'::text))::boolean) AND (jsonb_typeof((se.data -> 'return'::text)) = 'object'::text) AND (se.alter_time > (CURRENT_DATE - '1 day'::interval)))
ORDER BY se.alter_time DESC, dt.key DESC; ORDER BY se.alter_time DESC, dt.key DESC;
ALTER TABLE public.highstate_summary OWNER TO salt; ALTER TABLE public.highstate_errors OWNER TO salt;
-- --
-- Name: jids; Type: TABLE; Schema: public; Owner: salt -- Name: jids; Type: TABLE; Schema: public; Owner: salt
@ -252,6 +266,27 @@ ALTER TABLE ONLY public.salt_events
CREATE INDEX idx_alter_time ON public.salt_events USING btree (alter_time); CREATE INDEX idx_alter_time ON public.salt_events USING btree (alter_time);
--
-- Name: idx_fun; Type: INDEX; Schema: public; Owner: salt
--
CREATE INDEX idx_fun ON public.salt_events USING btree (((data ->> 'fun'::text)));
--
-- Name: idx_id; Type: INDEX; Schema: public; Owner: salt
--
CREATE INDEX idx_id ON public.salt_events USING btree (((data ->> 'id'::text)));
--
-- Name: idx_result; Type: INDEX; Schema: public; Owner: salt
--
CREATE INDEX idx_result ON public.salt_events USING btree (((data ->> 'result'::text)));
-- --
-- Name: idx_salt_events_tag; Type: INDEX; Schema: public; Owner: salt -- Name: idx_salt_events_tag; Type: INDEX; Schema: public; Owner: salt
-- --
@ -287,6 +322,14 @@ CREATE INDEX idx_salt_returns_jid ON public.salt_returns USING btree (jid);
CREATE INDEX idx_salt_returns_updated ON public.salt_returns USING btree (alter_time); CREATE INDEX idx_salt_returns_updated ON public.salt_returns USING btree (alter_time);
--
-- Name: idx_success; Type: INDEX; Schema: public; Owner: salt
--
CREATE INDEX idx_success ON public.salt_events USING btree (((data ->> 'success'::text)));
-- --
-- PostgreSQL database dump complete -- PostgreSQL database dump complete
-- --