From 7c2323fb6406b0a3c75393cdff0b1eee82b9f63f Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Fri, 10 Mar 2023 00:10:55 +0100 Subject: [PATCH] added salt sql ddl --- scripts/salt_schema.sql | 292 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 scripts/salt_schema.sql diff --git a/scripts/salt_schema.sql b/scripts/salt_schema.sql new file mode 100644 index 0000000..e810916 --- /dev/null +++ b/scripts/salt_schema.sql @@ -0,0 +1,292 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 13.10 (Debian 13.10-1.pgdg110+1) +-- Dumped by pg_dump version 13.10 (Debian 13.10-1.pgdg110+1) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: btree_gin; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS btree_gin WITH SCHEMA public; + + +-- +-- Name: EXTENSION btree_gin; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION btree_gin IS 'support for indexing common datatypes in GIN'; + + +-- +-- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public; + + +-- +-- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: +-- + +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 +-- + +CREATE FUNCTION public.archive_after_n_days(days integer) RETURNS void + LANGUAGE plpgsql + AS $$ +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); + DELETE FROM salt_events WHERE alter_time < current_date - format('%s day', days)::interval; +END; +$$; + + +ALTER FUNCTION public.archive_after_n_days(days integer) OWNER TO paul; + +-- +-- Name: delete_inc(text); Type: FUNCTION; Schema: public; Owner: paul +-- + +CREATE FUNCTION public.delete_inc(sdate text) RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + DELETE FROM salt_events_archive WHERE alter_time < TO_DATE(sdate, "%Y-%m-%d %H:%i:%s"); +END; +$$; + + +ALTER FUNCTION public.delete_inc(sdate text) OWNER TO paul; + +-- +-- Name: drop_archive_after_n_days(integer); Type: FUNCTION; Schema: public; Owner: paul +-- + +CREATE FUNCTION public.drop_archive_after_n_days(days integer) RETURNS void + LANGUAGE plpgsql + AS $$ +BEGIN + DELETE FROM salt_events_archive WHERE alter_time <= current_date - format('%s day', days)::interval; +END; +$$; + + +ALTER FUNCTION public.drop_archive_after_n_days(days integer) OWNER TO paul; + +-- +-- Name: seq_salt_events_id; Type: SEQUENCE; Schema: public; Owner: salt +-- + +CREATE SEQUENCE public.seq_salt_events_id + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.seq_salt_events_id OWNER TO salt; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: salt_events; Type: TABLE; Schema: public; Owner: salt +-- + +CREATE TABLE public.salt_events ( + id bigint DEFAULT nextval('public.seq_salt_events_id'::regclass) NOT NULL, + tag character varying(255) NOT NULL, + data jsonb NOT NULL, + alter_time timestamp with time zone DEFAULT now(), + master_id character varying(255) NOT NULL +); + + +ALTER TABLE public.salt_events OWNER TO salt; + +-- +-- Name: auth; Type: VIEW; Schema: public; Owner: salt +-- + +CREATE VIEW public.auth AS + SELECT salt_events.alter_time AS "time", + json_extract_path_text((salt_events.data)::json, VARIADIC ARRAY['id'::text]) AS hostname + FROM public.salt_events + WHERE ((salt_events.tag)::text = 'salt/auth'::text) + ORDER BY salt_events.alter_time DESC; + + +ALTER TABLE public.auth OWNER TO salt; + +-- +-- Name: highstate; Type: VIEW; Schema: public; Owner: salt +-- + +CREATE VIEW public.highstate AS + SELECT se.id, + se.tag, + se.data, + se.alter_time + FROM public.salt_events se + WHERE (jsonb_extract_path_text(se.data, VARIADIC ARRAY['fun'::text]) = 'state.highstate'::text) + ORDER BY se.id DESC + LIMIT 100; + + +ALTER TABLE public.highstate OWNER TO salt; + +-- +-- Name: highstate_summary; Type: VIEW; Schema: public; Owner: salt +-- + +CREATE VIEW public.highstate_summary AS + SELECT se.id, + se.tag, + se.alter_time AS "time", + (se.data ->> 'id'::text) AS hostname, + split_part(dt.key, '_|-'::text, 2) AS salt_state, + (dt.value ->> 'comment'::text) AS comment + FROM public.salt_events se, + 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))) + ORDER BY se.alter_time DESC, dt.key DESC; + + +ALTER TABLE public.highstate_summary OWNER TO salt; + +-- +-- Name: jids; Type: TABLE; Schema: public; Owner: salt +-- + +CREATE TABLE public.jids ( + jid character varying(20) NOT NULL, + load text NOT NULL +); + + +ALTER TABLE public.jids OWNER TO salt; + +-- +-- Name: pillar; Type: TABLE; Schema: public; Owner: salt +-- + +CREATE TABLE public.pillar ( + value1 character varying, + minion_pattern character varying +); + + +ALTER TABLE public.pillar OWNER TO salt; + +-- +-- Name: salt_events_archive; Type: TABLE; Schema: public; Owner: salt +-- + +CREATE TABLE public.salt_events_archive ( + id bigint NOT NULL, + tag character varying(255) NOT NULL, + data jsonb NOT NULL, + alter_time timestamp with time zone, + master_id character varying(255) NOT NULL +); + + +ALTER TABLE public.salt_events_archive OWNER TO salt; + +-- +-- Name: salt_returns; Type: TABLE; Schema: public; Owner: salt +-- + +CREATE TABLE public.salt_returns ( + fun character varying(50) NOT NULL, + jid character varying(255) NOT NULL, + return text NOT NULL, + full_ret text, + id character varying(255) NOT NULL, + success character varying(10) NOT NULL, + alter_time timestamp with time zone DEFAULT now() +); + + +ALTER TABLE public.salt_returns OWNER TO salt; + +-- +-- Name: jids jids_pkey; Type: CONSTRAINT; Schema: public; Owner: salt +-- + +ALTER TABLE ONLY public.jids + ADD CONSTRAINT jids_pkey PRIMARY KEY (jid); + + +-- +-- Name: salt_events salt_events_id_key; Type: CONSTRAINT; Schema: public; Owner: salt +-- + +ALTER TABLE ONLY public.salt_events + ADD CONSTRAINT salt_events_id_key UNIQUE (id); + + +-- +-- Name: idx_alter_time; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_alter_time ON public.salt_events USING btree (alter_time); + + +-- +-- Name: idx_salt_events_tag; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_salt_events_tag ON public.salt_events USING btree (tag); + + +-- +-- Name: idx_salt_returns_fun; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_salt_returns_fun ON public.salt_returns USING btree (fun); + + +-- +-- Name: idx_salt_returns_id; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_salt_returns_id ON public.salt_returns USING btree (id); + + +-- +-- Name: idx_salt_returns_jid; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_salt_returns_jid ON public.salt_returns USING btree (jid); + + +-- +-- Name: idx_salt_returns_updated; Type: INDEX; Schema: public; Owner: salt +-- + +CREATE INDEX idx_salt_returns_updated ON public.salt_returns USING btree (alter_time); + + +-- +-- PostgreSQL database dump complete +--