2020-08-08 23:59:13 +02:00
--
-- PostgreSQL database dump
--
2022-03-15 14:17:28 +01:00
-- Dumped from database version 14.2
2022-05-01 19:47:16 +02:00
-- Dumped by pg_dump version 14.2
2020-08-08 23:59:13 +02:00
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
--
2022-05-01 19:47:16 +02:00
CREATE DATABASE dougal WITH TEMPLATE = template0 ENCODING = ' UTF8 ' LOCALE = ' en_GB.UTF-8 ' ;
2020-08-08 23:59:13 +02:00
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 ' ;
2020-08-12 14:02:40 +02:00
--
-- Name: btree_gist; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public ;
--
2022-05-01 19:47:16 +02:00
-- Name: EXTENSION btree_gist; Type: COMMENT; Schema: -; Owner:
2020-08-12 14:02:40 +02:00
--
COMMENT ON EXTENSION btree_gist IS ' support for indexing common datatypes in GiST ' ;
2020-08-08 23:59:13 +02:00
--
-- Name: postgis; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public ;
--
2022-05-01 19:47:16 +02:00
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner:
2020-08-08 23:59:13 +02:00
--
COMMENT ON EXTENSION postgis IS ' PostGIS geometry, geography, and raster spatial types and functions ' ;
--
-- Name: postgis_sfcgal; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS postgis_sfcgal WITH SCHEMA public ;
--
2022-05-01 19:47:16 +02:00
-- Name: EXTENSION postgis_sfcgal; Type: COMMENT; Schema: -; Owner:
2020-08-08 23:59:13 +02:00
--
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 ;
--
2022-05-01 19:47:16 +02:00
-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner:
2020-08-08 23:59:13 +02:00
--
COMMENT ON EXTENSION postgis_topology IS ' PostGIS topology spatial types and functions ' ;
2022-03-15 14:17:28 +01:00
--
-- Name: queue_item_status; Type: TYPE; Schema: public; Owner: postgres
--
CREATE TYPE public . queue_item_status AS ENUM (
' queued ' ,
' cancelled ' ,
' failed ' ,
' sent '
) ;
ALTER TYPE public . queue_item_status OWNER TO postgres ;
2022-05-01 19:47:16 +02:00
--
-- Name: geometry_from_tstamp(timestamp with time zone, numeric); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public . geometry_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT geometry public . geometry , OUT delta numeric ) RETURNS record
LANGUAGE sql
AS $ $
SELECT
geometry ,
extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) AS delta
FROM real_time_inputs
WHERE
geometry IS NOT NULL AND
abs ( extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) ) < tolerance
ORDER BY abs ( extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) )
LIMIT 1 ;
$ $ ;
ALTER FUNCTION public . geometry_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT geometry public . geometry , OUT delta numeric ) OWNER TO postgres ;
--
-- Name: FUNCTION geometry_from_tstamp(ts timestamp with time zone, tolerance numeric, OUT geometry public.geometry, OUT delta numeric); Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON FUNCTION public . geometry_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT geometry public . geometry , OUT delta numeric ) IS ' Get geometry from timestamp ' ;
2020-09-03 13:59:51 +02:00
--
-- Name: notify(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public . notify ( ) RETURNS trigger
LANGUAGE plpgsql
AS $ $
DECLARE
channel text : = TG_ARGV [ 0 ] ;
2020-09-06 13:31:36 +02:00
payload text ;
2020-09-25 18:27:59 +02:00
pid text ;
2020-09-03 13:59:51 +02:00
BEGIN
2020-09-25 18:27:59 +02:00
SELECT projects . pid INTO pid FROM projects WHERE schema = TG_TABLE_SCHEMA ;
2020-09-06 13:31:36 +02:00
payload : = json_build_object (
2020-09-03 13:59:51 +02:00
' tstamp ' , CURRENT_TIMESTAMP ,
' operation ' , TG_OP ,
' schema ' , TG_TABLE_SCHEMA ,
' table ' , TG_TABLE_NAME ,
' old ' , row_to_json ( OLD ) ,
2020-09-25 18:27:59 +02:00
' new ' , row_to_json ( NEW ) ,
' pid ' , pid
2020-09-06 13:31:36 +02:00
) : : 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 ;
2020-09-03 13:59:51 +02:00
RETURN NULL ;
END ;
$ $ ;
ALTER FUNCTION public . notify ( ) OWNER TO postgres ;
2022-03-15 14:17:28 +01:00
--
-- Name: sequence_shot_from_tstamp(timestamp with time zone); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , OUT sequence numeric , OUT point numeric , OUT delta numeric ) RETURNS record
LANGUAGE sql
AS $ $
SELECT * FROM public . sequence_shot_from_tstamp ( ts , 3 ) ;
$ $ ;
ALTER FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , OUT sequence numeric , OUT point numeric , OUT delta numeric ) OWNER TO postgres ;
--
-- Name: FUNCTION sequence_shot_from_tstamp(ts timestamp with time zone, OUT sequence numeric, OUT point numeric, OUT delta numeric); Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , OUT sequence numeric , OUT point numeric , OUT delta numeric ) IS ' Get sequence and shotpoint from timestamp.
Overloaded form in which the tolerance value is implied and defaults to three seconds . ' ;
--
-- Name: sequence_shot_from_tstamp(timestamp with time zone, numeric); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT sequence numeric , OUT point numeric , OUT delta numeric ) RETURNS record
LANGUAGE sql
AS $ $
SELECT
( meta - > > ' _sequence ' ) : : numeric AS sequence ,
( meta - > > ' _point ' ) : : numeric AS point ,
extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) AS delta
FROM real_time_inputs
WHERE
meta ? ' _sequence ' AND
abs ( extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) ) < tolerance
ORDER BY abs ( extract ( ' epoch ' FROM ( meta - > > ' tstamp ' ) : : timestamptz - ts ) )
LIMIT 1 ;
$ $ ;
ALTER FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT sequence numeric , OUT point numeric , OUT delta numeric ) OWNER TO postgres ;
--
-- Name: FUNCTION sequence_shot_from_tstamp(ts timestamp with time zone, tolerance numeric, OUT sequence numeric, OUT point numeric, OUT delta numeric); Type: COMMENT; Schema: public; Owner: postgres
--
COMMENT ON FUNCTION public . sequence_shot_from_tstamp ( ts timestamp with time zone , tolerance numeric , OUT sequence numeric , OUT point numeric , OUT delta numeric ) IS ' Get sequence and shotpoint from timestamp.
Given a timestamp this function returns the closest shot to it within the given tolerance value .
This uses the ` real_time_inputs ` table and it does not give an indication of which project the shotpoint belongs to . It is assumed that a single project is being acquired at a given time . ' ;
2020-08-08 23:59:13 +02:00
--
-- Name: set_survey(text); Type: PROCEDURE; Schema: public; Owner: postgres
--
2022-03-15 14:17:28 +01:00
CREATE PROCEDURE public . set_survey ( IN project_id text )
2020-08-08 23:59:13 +02:00
LANGUAGE sql
AS $ $
2020-09-26 22:53:48 +02:00
SELECT set_config ( ' search_path ' , ( SELECT schema | | ' ,public ' FROM public . projects WHERE pid = lower ( project_id ) ) , false ) ;
2020-08-08 23:59:13 +02:00
$ $ ;
2022-03-15 14:17:28 +01:00
ALTER PROCEDURE public . set_survey ( IN project_id text ) OWNER TO postgres ;
--
-- Name: update_timestamp(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE FUNCTION public . update_timestamp ( ) RETURNS trigger
LANGUAGE plpgsql
AS $ $
BEGIN
IF NEW . updated_on IS NOT NULL THEN
NEW . updated_on : = current_timestamp ;
END IF ;
RETURN NEW ;
EXCEPTION
WHEN undefined_column THEN RETURN NEW ;
END ;
$ $ ;
ALTER FUNCTION public . update_timestamp ( ) OWNER TO postgres ;
2020-08-08 23:59:13 +02:00
SET default_tablespace = ' ' ;
2020-08-31 14:31:12 +02:00
SET default_table_access_method = heap ;
2022-03-15 14:17:28 +01:00
--
-- Name: info; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public . info (
key text NOT NULL ,
value jsonb
) ;
ALTER TABLE public . info OWNER TO postgres ;
2020-08-08 23:59:13 +02:00
--
-- Name: projects; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public . projects (
pid text NOT NULL ,
name text NOT NULL ,
2020-09-06 13:31:36 +02:00
schema text NOT NULL ,
meta jsonb DEFAULT ' {} ' : : jsonb NOT NULL
2020-08-08 23:59:13 +02:00
) ;
ALTER TABLE public . projects OWNER TO postgres ;
2022-03-15 14:17:28 +01:00
--
-- Name: queue_items; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public . queue_items (
item_id integer NOT NULL ,
status public . queue_item_status DEFAULT ' queued ' : : public . queue_item_status NOT NULL ,
payload jsonb NOT NULL ,
results jsonb DEFAULT ' {} ' : : jsonb NOT NULL ,
created_on timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL ,
updated_on timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL ,
not_before timestamp with time zone DEFAULT ' 1970-01-01 00:00:00+00 ' : : timestamp with time zone NOT NULL ,
parent_id integer
) ;
ALTER TABLE public . queue_items OWNER TO postgres ;
--
-- Name: queue_items_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--
CREATE SEQUENCE public . queue_items_item_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1 ;
ALTER TABLE public . queue_items_item_id_seq OWNER TO postgres ;
--
-- Name: queue_items_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--
ALTER SEQUENCE public . queue_items_item_id_seq OWNED BY public . queue_items . item_id ;
2020-08-31 14:31:12 +02:00
--
-- 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 ;
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
-- Name: queue_items item_id; Type: DEFAULT; Schema: public; Owner: postgres
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
ALTER TABLE ONLY public . queue_items ALTER COLUMN item_id SET DEFAULT nextval ( ' public.queue_items_item_id_seq ' : : regclass ) ;
2021-05-20 18:07:05 +02:00
2022-03-15 14:17:28 +01:00
--
-- Name: info info_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public . info
ADD CONSTRAINT info_pkey PRIMARY KEY ( key ) ;
2021-05-20 18:07:05 +02:00
2020-08-08 23:59:13 +02:00
--
-- 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 ) ;
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
-- Name: queue_items queue_items_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
ALTER TABLE ONLY public . queue_items
ADD CONSTRAINT queue_items_pkey PRIMARY KEY ( item_id ) ;
2021-05-20 18:07:05 +02:00
2022-05-01 19:47:16 +02:00
--
-- Name: meta_tstamp_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX meta_tstamp_idx ON public . real_time_inputs USING btree ( ( ( meta - > > ' tstamp ' : : text ) ) DESC ) ;
2020-08-31 14:31:12 +02:00
--
-- Name: tstamp_idx; Type: INDEX; Schema: public; Owner: postgres
--
CREATE INDEX tstamp_idx ON public . real_time_inputs USING btree ( tstamp DESC ) ;
2022-03-15 14:17:28 +01:00
--
-- Name: info info_tg; Type: TRIGGER; Schema: public; Owner: postgres
--
CREATE TRIGGER info_tg AFTER INSERT OR DELETE OR UPDATE ON public . info FOR EACH ROW EXECUTE FUNCTION public . notify ( ' info ' ) ;
2020-09-03 14:00:59 +02:00
--
-- 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 ' ) ;
2022-03-15 14:17:28 +01:00
--
-- Name: queue_items queue_items_tg0; Type: TRIGGER; Schema: public; Owner: postgres
--
CREATE TRIGGER queue_items_tg0 BEFORE INSERT OR UPDATE ON public . queue_items FOR EACH ROW EXECUTE FUNCTION public . update_timestamp ( ) ;
--
-- Name: queue_items queue_items_tg1; Type: TRIGGER; Schema: public; Owner: postgres
--
CREATE TRIGGER queue_items_tg1 AFTER INSERT OR DELETE OR UPDATE ON public . queue_items FOR EACH ROW EXECUTE FUNCTION public . notify ( ' queue_items ' ) ;
2020-09-03 14:01:41 +02:00
--
-- 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 ' ) ;
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
-- Name: queue_items queue_items_parent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
2021-05-20 18:07:05 +02:00
--
2022-03-15 14:17:28 +01:00
ALTER TABLE ONLY public . queue_items
ADD CONSTRAINT queue_items_parent_id_fkey FOREIGN KEY ( parent_id ) REFERENCES public . queue_items ( item_id ) ;
2022-05-01 19:47:16 +02:00
2020-08-08 23:59:13 +02:00
--
-- PostgreSQL database dump complete
--