oedb-backend/setup.sql

163 lines
3.4 KiB
MySQL
Raw Normal View History

2016-04-14 16:53:36 +02:00
--
-- PostgreSQL database dump
--
2016-08-07 17:09:52 +02:00
-- Dumped from database version 9.5.3
-- Dumped by pg_dump version 9.5.3
2016-04-14 16:53:36 +02:00
2025-09-18 14:50:30 +02:00
CREATE ROLE "cipherbliss";
ALTER ROLE "cipherbliss" WITH LOGIN;
-- pass à changer selon les données du fichier .env
-- alter USER cipherbliss with password '1234';
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO cipherbliss;
GRANT ALL PRIVILEGES ON DATABASE oedb TO cipherbliss;
2025-09-18 19:09:25 +02:00
2016-09-26 16:12:59 +02:00
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "postgis";
2016-04-14 16:53:36 +02:00
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: events; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE events (
2016-04-14 19:05:59 +02:00
events_id uuid DEFAULT uuid_generate_v4(),
2016-04-20 07:48:58 +02:00
createdate timestamp without time zone DEFAULT now(),
2016-04-30 23:50:28 +02:00
lastupdate timestamp without time zone,
2016-05-06 17:04:52 +02:00
events_type text,
events_what text,
events_when tstzrange,
events_geo text,
2016-05-06 17:04:52 +02:00
events_tags jsonb
2016-04-30 23:50:28 +02:00
);
CREATE TABLE events_deleted (
events_id uuid,
createdate timestamp without time zone,
lastupdate timestamp without time zone,
events_type text,
events_what text,
events_when tstzrange,
events_geo text,
events_tags jsonb
);
2016-04-30 23:50:28 +02:00
--
-- Name: geo; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE geo (
geom geometry(Geometry,4326),
2016-08-07 17:09:52 +02:00
hash text,
geom_center geometry(Point,4326),
2016-08-07 17:09:52 +02:00
idx geometry
2016-04-14 16:53:36 +02:00
);
2016-04-20 07:48:58 +02:00
--
2016-04-30 23:50:28 +02:00
-- Name: geo_hash_key; Type: CONSTRAINT; Schema: public; Owner: -
2016-04-20 07:48:58 +02:00
--
2016-04-30 23:50:28 +02:00
ALTER TABLE ONLY geo
ADD CONSTRAINT geo_hash_key UNIQUE (hash);
2016-04-20 07:48:58 +02:00
2016-08-07 17:09:52 +02:00
--
-- Name: events_idx_antidup; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX events_idx_antidup ON events USING btree (events_geo, events_what, events_when);
2016-04-14 19:05:59 +02:00
--
-- Name: events_idx_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX events_idx_id ON events USING btree (events_id);
2016-04-20 07:48:58 +02:00
--
-- Name: events_idx_lastupdate; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX events_idx_lastupdate ON events USING btree (lastupdate);
2016-04-14 16:53:36 +02:00
--
-- Name: events_idx_what; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX events_idx_what ON events USING spgist (events_what);
--
-- Name: events_idx_when; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX events_idx_when ON events USING spgist (events_when);
2016-04-14 16:53:36 +02:00
--
2016-04-30 23:50:28 +02:00
-- Name: geo_geom; Type: INDEX; Schema: public; Owner: -
2016-04-14 16:53:36 +02:00
--
2016-04-30 23:50:28 +02:00
CREATE INDEX geo_geom ON geo USING gist (geom);
2016-04-14 16:53:36 +02:00
2016-08-07 17:09:52 +02:00
--
-- Name: geo_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX geo_idx ON geo USING gist (idx);
2016-04-20 07:48:58 +02:00
--
-- Name: events_lastupdate_trigger; Type: TRIGGER; Schema: public; Owner: -
--
2016-09-26 16:12:59 +02:00
CREATE FUNCTION events_lastupdate() RETURNS trigger AS $$
BEGIN
NEW.lastupdate := NOW();
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
2016-04-30 23:50:28 +02:00
CREATE TRIGGER events_lastupdate_trigger BEFORE INSERT OR UPDATE ON events FOR EACH ROW EXECUTE PROCEDURE events_lastupdate();
2016-04-20 07:48:58 +02:00
2016-04-14 16:53:36 +02:00
--
2016-04-30 23:50:28 +02:00
-- Name: geo_pk; Type: FK CONSTRAINT; Schema: public; Owner: -
2016-04-14 16:53:36 +02:00
--
2016-04-30 23:50:28 +02:00
ALTER TABLE ONLY events
ADD CONSTRAINT geo_pk FOREIGN KEY (events_geo) REFERENCES geo(hash);
2016-04-14 16:53:36 +02:00
--
-- PostgreSQL database dump complete
--
CREATE INDEX events_idx_where_osm ON events USING spgist ((events_tags->>'where:osm')) WHERE events_tags ? 'where:osm';
CREATE INDEX events_idx_where_wikidata ON events USING spgist ((events_tags->>'where:wikidata')) WHERE events_tags ? 'where:wikidata';