mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:27:07 +00:00
278 lines
6.0 KiB
PL/PgSQL
278 lines
6.0 KiB
PL/PgSQL
--
|
|
-- PostgreSQL database dump
|
|
--
|
|
|
|
-- Dumped from database version 12.4
|
|
-- Dumped by pg_dump version 12.4
|
|
|
|
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: dougal; Type: DATABASE; Schema: -; Owner: postgres
|
|
--
|
|
|
|
CREATE DATABASE dougal WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C' LC_CTYPE = 'en_GB.UTF-8';
|
|
|
|
|
|
ALTER DATABASE dougal OWNER TO postgres;
|
|
|
|
\connect dougal
|
|
|
|
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: dougal; Type: DATABASE PROPERTIES; Schema: -; Owner: postgres
|
|
--
|
|
|
|
ALTER DATABASE dougal SET search_path TO '$user', 'public', 'topology';
|
|
|
|
|
|
\connect dougal
|
|
|
|
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: topology; Type: SCHEMA; Schema: -; Owner: postgres
|
|
--
|
|
|
|
CREATE SCHEMA topology;
|
|
|
|
|
|
ALTER SCHEMA topology OWNER TO postgres;
|
|
|
|
--
|
|
-- Name: SCHEMA topology; Type: COMMENT; Schema: -; Owner: postgres
|
|
--
|
|
|
|
COMMENT ON SCHEMA topology IS 'PostGIS Topology schema';
|
|
|
|
|
|
--
|
|
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
|
|
--
|
|
|
|
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
|
|
|
|
|
|
--
|
|
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner:
|
|
--
|
|
|
|
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';
|
|
|
|
|
|
--
|
|
-- Name: postgis; Type: EXTENSION; Schema: -; Owner: -
|
|
--
|
|
|
|
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;
|
|
|
|
|
|
--
|
|
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner:
|
|
--
|
|
|
|
COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions';
|
|
|
|
|
|
--
|
|
-- Name: postgis_raster; Type: EXTENSION; Schema: -; Owner: -
|
|
--
|
|
|
|
CREATE EXTENSION IF NOT EXISTS postgis_raster WITH SCHEMA public;
|
|
|
|
|
|
--
|
|
-- Name: EXTENSION postgis_raster; Type: COMMENT; Schema: -; Owner:
|
|
--
|
|
|
|
COMMENT ON EXTENSION postgis_raster IS 'PostGIS raster types and functions';
|
|
|
|
|
|
--
|
|
-- Name: postgis_sfcgal; Type: EXTENSION; Schema: -; Owner: -
|
|
--
|
|
|
|
CREATE EXTENSION IF NOT EXISTS postgis_sfcgal WITH SCHEMA public;
|
|
|
|
|
|
--
|
|
-- Name: EXTENSION postgis_sfcgal; Type: COMMENT; Schema: -; Owner:
|
|
--
|
|
|
|
COMMENT ON EXTENSION postgis_sfcgal IS 'PostGIS SFCGAL functions';
|
|
|
|
|
|
--
|
|
-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: -
|
|
--
|
|
|
|
CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology;
|
|
|
|
|
|
--
|
|
-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner:
|
|
--
|
|
|
|
COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions';
|
|
|
|
|
|
--
|
|
-- Name: notify(); Type: FUNCTION; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE FUNCTION public.notify() RETURNS trigger
|
|
LANGUAGE plpgsql
|
|
AS $$
|
|
DECLARE
|
|
channel text := TG_ARGV[0];
|
|
payload text;
|
|
pid text;
|
|
BEGIN
|
|
|
|
SELECT projects.pid INTO pid FROM projects WHERE schema = TG_TABLE_SCHEMA;
|
|
|
|
payload := json_build_object(
|
|
'tstamp', CURRENT_TIMESTAMP,
|
|
'operation', TG_OP,
|
|
'schema', TG_TABLE_SCHEMA,
|
|
'table', TG_TABLE_NAME,
|
|
'old', row_to_json(OLD),
|
|
'new', row_to_json(NEW),
|
|
'pid', pid
|
|
)::text;
|
|
|
|
IF octet_length(payload) < 8000 THEN
|
|
PERFORM pg_notify(channel, payload);
|
|
ELSE
|
|
-- We need to find another solution
|
|
RAISE INFO 'Payload over limit';
|
|
END IF;
|
|
RETURN NULL;
|
|
END;
|
|
$$;
|
|
|
|
|
|
ALTER FUNCTION public.notify() OWNER TO postgres;
|
|
|
|
--
|
|
-- Name: set_survey(text); Type: PROCEDURE; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE PROCEDURE public.set_survey(project_id text)
|
|
LANGUAGE sql
|
|
AS $$
|
|
SELECT set_config('search_path', (SELECT schema||',public' FROM public.projects WHERE pid = lower(project_id)), false);
|
|
$$;
|
|
|
|
|
|
ALTER PROCEDURE public.set_survey(project_id text) OWNER TO postgres;
|
|
|
|
SET default_tablespace = '';
|
|
|
|
SET default_table_access_method = heap;
|
|
|
|
--
|
|
-- Name: projects; Type: TABLE; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE TABLE public.projects (
|
|
pid text NOT NULL,
|
|
name text NOT NULL,
|
|
schema text NOT NULL,
|
|
meta jsonb DEFAULT '{}'::jsonb NOT NULL
|
|
);
|
|
|
|
|
|
ALTER TABLE public.projects OWNER TO postgres;
|
|
|
|
--
|
|
-- Name: real_time_inputs; Type: TABLE; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE TABLE public.real_time_inputs (
|
|
tstamp timestamp with time zone NOT NULL,
|
|
geometry public.geometry(Point,4326),
|
|
meta jsonb
|
|
);
|
|
|
|
|
|
ALTER TABLE public.real_time_inputs OWNER TO postgres;
|
|
|
|
--
|
|
-- Name: projects projects_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
|
--
|
|
|
|
ALTER TABLE ONLY public.projects
|
|
ADD CONSTRAINT projects_name_key UNIQUE (name);
|
|
|
|
|
|
--
|
|
-- Name: projects projects_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
|
--
|
|
|
|
ALTER TABLE ONLY public.projects
|
|
ADD CONSTRAINT projects_pkey PRIMARY KEY (pid);
|
|
|
|
|
|
--
|
|
-- Name: projects projects_schema_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
|
--
|
|
|
|
ALTER TABLE ONLY public.projects
|
|
ADD CONSTRAINT projects_schema_key UNIQUE (schema);
|
|
|
|
|
|
--
|
|
-- Name: tstamp_idx; Type: INDEX; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE INDEX tstamp_idx ON public.real_time_inputs USING btree (tstamp DESC);
|
|
|
|
|
|
--
|
|
-- Name: projects projects_tg; Type: TRIGGER; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE TRIGGER projects_tg AFTER INSERT OR DELETE OR UPDATE ON public.projects FOR EACH ROW EXECUTE FUNCTION public.notify('project');
|
|
|
|
|
|
--
|
|
-- Name: real_time_inputs real_time_inputs_tg; Type: TRIGGER; Schema: public; Owner: postgres
|
|
--
|
|
|
|
CREATE TRIGGER real_time_inputs_tg AFTER INSERT ON public.real_time_inputs FOR EACH ROW EXECUTE FUNCTION public.notify('realtime');
|
|
|
|
|
|
--
|
|
-- PostgreSQL database dump complete
|
|
--
|
|
|