From 0fc32a4435588809c2fa842cd56dfb0a51db0788 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Wed, 2 Mar 2022 17:04:24 +0100 Subject: [PATCH 01/13] db auth --- .../column-builder/backend/bin/run-tests | 2 +- .../column-builder/backend/requirements.txt | 4 +- .../column-builder/backend/tests/conftest.py | 2 + .../backend/tests/test_z_auth.py | 82 +- .../backend/urvogel/database/bin/dump-data | 9 + .../urvogel/database/fixtures/auth.sql | 114 ++- .../urvogel/database/fixtures/schema_dump.sql | 758 ++++++++++++++---- .../database/fixtures/test_inserts.sql | 37 + .../database/fixtures/01-views.sql | 9 +- .../column-builder/docker-compose.yaml | 1 + 10 files changed, 848 insertions(+), 170 deletions(-) create mode 100755 v2-transition/services/column-builder/backend/urvogel/database/bin/dump-data diff --git a/v2-transition/services/column-builder/backend/bin/run-tests b/v2-transition/services/column-builder/backend/bin/run-tests index 5d0da6449..9fc334812 100755 --- a/v2-transition/services/column-builder/backend/bin/run-tests +++ b/v2-transition/services/column-builder/backend/bin/run-tests @@ -8,7 +8,7 @@ result=$( docker ps -q -f name=postgrest ) if [[ -n "$result" ]]; then echo "Rebuilding Postgrest Docker container for testing!" - POSTGRES_DB=col_test docker-compose up -d --build postgrest + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon docker-compose up -d --build postgrest else echo "Starting Docker" POSTGRES_DB=col_test docker-compose up -d diff --git a/v2-transition/services/column-builder/backend/requirements.txt b/v2-transition/services/column-builder/backend/requirements.txt index 5c1172a2d..e59dff5de 100644 --- a/v2-transition/services/column-builder/backend/requirements.txt +++ b/v2-transition/services/column-builder/backend/requirements.txt @@ -7,4 +7,6 @@ fastapi geojson_pydantic requests uvicorn -pytest \ No newline at end of file +pytest +pyjwt +requests_jwt \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/tests/conftest.py b/v2-transition/services/column-builder/backend/tests/conftest.py index 774352c28..296a2ff49 100644 --- a/v2-transition/services/column-builder/backend/tests/conftest.py +++ b/v2-transition/services/column-builder/backend/tests/conftest.py @@ -30,6 +30,8 @@ def setup(db_): with db_.conn.cursor() as cur: cur.execute("DROP SCHEMA IF EXISTS macrostrat_api CASCADE;") cur.execute("DROP SCHEMA IF EXISTS macrostrat CASCADE;") + cur.execute("DROP TYPE IF EXISTS measurement_type CASCADE;") + cur.execute("DROP TYPE IF EXISTS measurement_class CASCADE;") cur.execute(schema) cur.execute(data_inserts) diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index b3e3e2839..be37c60ba 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -1,17 +1,18 @@ +from email import header from requests import get, post, patch, put from urvogel.database.fixtures import get_sql from psycopg.sql import SQL, Literal - base= "http://127.0.0.1:3001" auth = get_sql("auth.sql") auth_inserts = get_sql("test_auth_inserts.sql") +email = "cidzikowski@wisc.edu" +password = "gniessrocks" def test_create_auth(db): with db.conn.cursor() as cur: cur.execute(auth) - ##cur.execute(auth_inserts) sql =""" SELECT EXISTS ( SELECT FROM information_schema.tables @@ -28,4 +29,79 @@ def test_create_auth(db): res = db.query(sql).fetchall() for row in res: - assert row.get('rolname') in ['reader', 'writer', 'deleter', 'owner_'] \ No newline at end of file + assert row.get('rolname') in ['reader', 'writer', 'deleter', 'owner_','anon','authenticator', 'new_user'] + +def test_pg_extensions(db): + sql = """ select extname from pg_extension; """ + res = db.query(sql).fetchall() + extensions = [r.get('extname') for r in res] + assert 'pgcrypto' in extensions + assert 'pgjwt' in extensions + +def test_add_user(db): + + params = {"email": email, "pass": password} + res = post(base+"/rpc/create_user", data=params) + + assert res.status_code == 200 + + sql = """ + SELECT email from auth.users; + """ + res = db.query(sql).fetchone() + assert res.get('email') is not None + +def test_login(db): + + res = post(base+"/rpc/login", data={"email": email, "pass": password}) + + assert res.status_code == 200 + + token = res.json().get('token') + assert token is not None + headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} + + res = post(base + "/rpc/get_email", headers=headers) + + assert res.json() == email + + res = get(base + "/projects", headers=headers) + data = res.json() + + assert len(data) == 0 + + # make the user an owner + sql = """ insert into auth.user_projects(user_, project, role) + values(1, 1, 'owner_') """ + + with db.conn.cursor() as cur: + cur.execute(sql) + + res = post(base + '/rpc/current_user_projects', headers=headers) + assert len(res.json()) == 1 and res.json()[0].get('id') == 1 + + res = get(base + "/projects", headers={"Prefer": "return=representation", "Authorization": f'bearer {token}'}) + data = res.json() + + assert len(data) == 1 and data[0].get('id') == 1 + +def test_project_create(db): + res = post(base+"/rpc/login", data={"email": email, "pass": password}) + + assert res.status_code == 200 + + token = res.json().get('token') + assert token is not None + headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} + + ## Can't insert into the view bc it was created from a function! + res = post(base + "/projects", headers=headers, data={"project":"CFP1", "descrip":"fake project owned by casey", "timescale_id": 1}) + + assert res.status_code == 200 + res = get(base + "/projects", headers=headers) + data = res.json() + + assert len(data) == 2 + + + diff --git a/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-data b/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-data new file mode 100755 index 000000000..d99ff26da --- /dev/null +++ b/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-data @@ -0,0 +1,9 @@ +#!/usr/bin/env zsh + +echo "Removing old schema dump if it exists!!" +rm -f `dirname $0`/../fixtures/schema_dump.sql + +echo "" +echo "" +echo "Dumping the new schema" +docker-compose exec db pg_dump -U postgres -d column_data > `dirname $0`/../fixtures/data_dump.sql \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index 9f4d83a65..8bb199ef3 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -56,22 +56,32 @@ current_setting('request.jwt.claims', true)::json->>'email'; */ -/* necesary extenstions */ -CREATE EXTENSION IF NOT EXISTS pgcrypto; -CREATE EXTENSION IF NOT EXISTS pgjwt; - /* AUTH schema and functions */ DROP SCHEMA auth CASCADE; CREATE SCHEMA auth; + +/* necesary extenstions */ +CREATE EXTENSION IF NOT EXISTS pgcrypto; +CREATE EXTENSION IF NOT EXISTS pgjwt; + /* an auth user table */ CREATE TABLE IF NOT EXISTS auth.users( - email text primary key check ( email ~* '^.+@.+\..+$' ), - pass text not null check (length(pass) < 512), - projects integer[], - role name not null check (length(role) < 512) + id serial primary key, + email text check ( email ~* '^.+@.+\..+$' ), + pass text not null check (length(pass) < 512), + role name not null check (length(role) < 512) +); + +/* Example of a basic data id to role */ +CREATE TABLE IF NOT EXISTS +auth.user_projects( + id serial primary key, + user_ int REFERENCES auth.users(id), + project int REFERENCES macrostrat.projects(id), + role name not null check (length(role) < 512) ); /* make sure the role being added to user table actually exists!! */ @@ -88,8 +98,8 @@ END $$ LANGUAGE plpgsql; DROP trigger IF EXISTS ensure_user_role_exists ON auth.users; -CREATE CONSTRAINT trigger ensure_user_role_exists - AFTER INSERT OR UPDATE ON auth.users +CREATE trigger ensure_user_role_exists + BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE PROCEDURE auth.check_role_exists(); @@ -99,15 +109,15 @@ CREATE OR REPLACE FUNCTION auth.encrypt_pass() RETURNS trigger AS $$ BEGIN IF tg_op = 'INSERT' OR new.pass <> old.pass THEN - new.pass = crypt(new.pass, gen_salt('md5')); + new.pass := public.crypt(new.pass, public.gen_salt('md5')); END IF; RETURN new; END $$ LANGUAGE plpgsql; DROP trigger IF EXISTS encrypt_pass ON auth.users; -CREATE CONSTRAINT trigger encrypt_pass - AFTER INSERT OR UPDATE ON auth.users +CREATE trigger encrypt_pass + BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE PROCEDURE auth.encrypt_pass(); @@ -122,7 +132,7 @@ BEGIN RETURN ( SELECT role FROM auth.users WHERE users.email = user_role.email - AND users.pass = crypt(user_role.pass, users.pass) + AND users.pass = public.crypt(user_role.pass, users.pass) ); END; $$; @@ -146,7 +156,7 @@ BEGIN END IF; -- sign function comes from pgjwt extension. SELECT sign( - row_to_json(r), 'reallyreallyreallyreallyverysafe' + row_to_json(r), 'reallyreallyreallyreallyverysafesafesafesafe' ) AS token FROM ( SELECT _role as role, login.email as email, @@ -158,12 +168,12 @@ END $$ language plpgsql SECURITY DEFINER; CREATE OR REPLACE FUNCTION -macrostrat_api.create_user(email text, pass text, role_ text) RETURNS BOOLEAN AS $$ +macrostrat_api.create_user(email text, pass text) RETURNS BOOLEAN AS $$ DECLARE _role name; BEGIN INSERT INTO auth.users(email, pass, role) - VALUES (email, pass, role_); + VALUES (email, public.crypt(pass, public.gen_salt('md5')), 'new_user'); SELECT auth.user_role(email, pass) INTO _role; IF _role IS NULL THEN @@ -177,6 +187,16 @@ $$ language plpgsql SECURITY DEFINER; /*####################### BASE DB ROLES ##########################*/ +-- these are the basic auth roles used by postgrest. +DROP ROLE IF EXISTS anon; +CREATE ROLE anon NOINHERIT; +DROP ROLE IF EXISTS authenticator; +CREATE ROLE authenticator NOINHERIT; +GRANT anon TO authenticator; + +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; + -- read only DROP ROLE IF EXISTS reader; CREATE ROLE reader NOINHERIT; @@ -203,6 +223,66 @@ GRANT USAGE ON SCHEMA auth TO owner_; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO owner_; GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO owner_; +-- a new user has only the option to create a new project +DROP ROLE IF EXISTS new_user; +CREATE ROLE new_user NOINHERIT; +GRANT USAGE ON SCHEMA macrostrat_api TO new_user; +GRANT USAGE ON SCHEMA macrostrat TO new_user; +GRANT USAGE ON SCHEMA auth TO new_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO new_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO new_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO new_user; /* ################### Row level policies ################### */ +/* function to get email off of jwt claims*/ +CREATE OR REPLACE FUNCTION +macrostrat_api.get_email() returns text AS $$ +DECLARE + email_ text; +BEGIN + SELECT current_setting('request.jwt.claims', true)::json->>'email' INTO email_; +RETURN email_; +END +$$language plpgsql SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION +auth.user_project_insert() RETURNS trigger AS $$ +DECLARE + email_ text; + id_ +BEGIN + IF tg_op = 'INSERT' THEN + select macrostrat_api.get_email() into email_; + select id from auth.users where users.email = email_ INTO id_; + INSERT INTO auth.user_pojects(user, project, role_) + VALUES(id_, new.id, "owner_"); + END IF; + RETURN new; +END +$$ LANGUAGE plpgsql; + +DROP trigger IF EXISTS encrypt_pass ON auth.users; +CREATE trigger user_pojects + AFTER INSERT ON macrostrat.projects + FOR EACH ROW + EXECUTE PROCEDURE auth.user_project_insert(); + + +CREATE OR REPLACE FUNCTION +macrostrat_api.current_user_projects() RETURNS TABLE(id int) AS $$ +DECLARE + email_ text; +BEGIN + SELECT macrostrat_api.get_email() INTO email_; + RETURN QUERY + SELECT project FROM auth.user_projects + JOIN auth.users u + on u.email = email_; +END +$$ language plpgsql SECURITY DEFINER; + +ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; + +CREATE POLICY projects_ ON macrostrat.projects FOR SELECT +USING (id IN (SELECT macrostrat_api.current_user_projects())); \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql index 8dfd66f9c..f6aee4b65 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql @@ -48,6 +48,39 @@ CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; COMMENT ON EXTENSION postgis IS 'PostGIS geometry and geography spatial types and functions'; +-- +-- Name: measurement_class; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.measurement_class AS ENUM ( + '', + 'geophysical', + 'geochemical', + 'sedimentological' +); + + +ALTER TYPE public.measurement_class OWNER TO postgres; + +-- +-- Name: measurement_type; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.measurement_type AS ENUM ( + '', + 'material properties', + 'geochronological', + 'major elements', + 'minor elements', + 'radiogenic isotopes', + 'stable isotopes', + 'petrologic', + 'environmental' +); + + +ALTER TYPE public.measurement_type OWNER TO postgres; + -- -- Name: make_into_serial(text, text); Type: FUNCTION; Schema: macrostrat; Owner: postgres -- @@ -119,6 +152,42 @@ SET default_tablespace = ''; SET default_table_access_method = heap; +-- +-- Name: projects; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.projects ( + id integer NOT NULL, + project text, + descrip text, + timescale_id integer +); + + +ALTER TABLE macrostrat.projects OWNER TO postgres; + +-- +-- Name: TABLE projects; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.projects IS 'Last updated from MariaDB - 2022-02-25 14:40'; + + +-- +-- Name: get_projects(); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- + +CREATE FUNCTION macrostrat_api.get_projects() RETURNS SETOF macrostrat.projects + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.projects; +END +$$; + + +ALTER FUNCTION macrostrat_api.get_projects() OWNER TO postgres; + -- -- Name: autocomplete; Type: TABLE; Schema: macrostrat; Owner: postgres -- @@ -137,7 +206,7 @@ ALTER TABLE macrostrat.autocomplete OWNER TO postgres; -- Name: TABLE autocomplete; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.autocomplete IS 'Last updated from MariaDB - 2021-08-30 11:28'; +COMMENT ON TABLE macrostrat.autocomplete IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -147,7 +216,7 @@ COMMENT ON TABLE macrostrat.autocomplete IS 'Last updated from MariaDB - 2021-08 CREATE TABLE macrostrat.col_areas ( id integer NOT NULL, col_id integer, - col_area public.geometry(Geometry,4326), + col_area public.geometry, wkt text ); @@ -158,7 +227,7 @@ ALTER TABLE macrostrat.col_areas OWNER TO postgres; -- Name: TABLE col_areas; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.col_areas IS 'Last updated from MariaDB - 2021-08-30 11:30'; +COMMENT ON TABLE macrostrat.col_areas IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -241,7 +310,7 @@ ALTER TABLE macrostrat.col_refs OWNER TO postgres; -- Name: TABLE col_refs; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.col_refs IS 'Last updated from MariaDB - 2021-08-30 11:25'; +COMMENT ON TABLE macrostrat.col_refs IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -281,10 +350,11 @@ CREATE TABLE macrostrat.cols ( lat numeric, lng numeric, col_area numeric, - coordinate public.geometry(Geometry,4326), + coordinate public.geometry, wkt text, created text, - poly_geom public.geometry(Geometry,4326) + poly_geom public.geometry, + notes text ); @@ -294,7 +364,7 @@ ALTER TABLE macrostrat.cols OWNER TO postgres; -- Name: TABLE cols; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.cols IS 'Last updated from MariaDB - 2021-08-30 12:02'; +COMMENT ON TABLE macrostrat.cols IS 'Last updated from MariaDB - 2022-02-25 14:47'; -- @@ -334,7 +404,7 @@ ALTER TABLE macrostrat.concepts_places OWNER TO postgres; -- Name: TABLE concepts_places; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.concepts_places IS 'Last updated from MariaDB - 2021-08-30 11:25'; +COMMENT ON TABLE macrostrat.concepts_places IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -356,7 +426,7 @@ ALTER TABLE macrostrat.econs OWNER TO postgres; -- Name: TABLE econs; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.econs IS 'Last updated from MariaDB - 2021-08-30 11:25'; +COMMENT ON TABLE macrostrat.econs IS 'Last updated from MariaDB - 2022-02-25 14:29'; -- @@ -484,7 +554,7 @@ ALTER TABLE macrostrat.intervals OWNER TO postgres; -- Name: TABLE intervals; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.intervals IS 'Last updated from MariaDB - 2021-08-30 11:29'; +COMMENT ON TABLE macrostrat.intervals IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -509,10 +579,10 @@ ALTER SEQUENCE macrostrat.intervals_id_seq OWNED BY macrostrat.intervals.id; -- --- Name: intervals_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- -CREATE SEQUENCE macrostrat.intervals_new_id_seq1 +CREATE SEQUENCE macrostrat.intervals_new_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -521,13 +591,13 @@ CREATE SEQUENCE macrostrat.intervals_new_id_seq1 CACHE 1; -ALTER TABLE macrostrat.intervals_new_id_seq1 OWNER TO postgres; +ALTER TABLE macrostrat.intervals_new_id_seq OWNER TO postgres; -- --- Name: intervals_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres -- -ALTER SEQUENCE macrostrat.intervals_new_id_seq1 OWNED BY macrostrat.intervals.id; +ALTER SEQUENCE macrostrat.intervals_new_id_seq OWNED BY macrostrat.intervals.id; -- @@ -597,7 +667,7 @@ ALTER TABLE macrostrat.liths OWNER TO postgres; -- Name: TABLE liths; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.liths IS 'Last updated from MariaDB - 2021-08-30 11:29'; +COMMENT ON TABLE macrostrat.liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -680,7 +750,7 @@ ALTER TABLE macrostrat.lookup_unit_attrs_api OWNER TO postgres; -- Name: TABLE lookup_unit_attrs_api; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.lookup_unit_attrs_api IS 'Last updated from MariaDB - 2021-08-30 11:30'; +COMMENT ON TABLE macrostrat.lookup_unit_attrs_api IS 'Last updated from MariaDB - 2022-02-25 14:29'; -- @@ -742,7 +812,7 @@ ALTER TABLE macrostrat.lookup_unit_liths OWNER TO postgres; -- Name: TABLE lookup_unit_liths; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.lookup_unit_liths IS 'Last updated from MariaDB - 2021-08-30 11:24'; +COMMENT ON TABLE macrostrat.lookup_unit_liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -818,6 +888,48 @@ ALTER TABLE macrostrat.lookup_units_unit_id_seq OWNER TO postgres; ALTER SEQUENCE macrostrat.lookup_units_unit_id_seq OWNED BY macrostrat.lookup_units.unit_id; +-- +-- Name: measurements; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.measurements ( + id integer NOT NULL, + measurement_class public.measurement_class NOT NULL, + measurement_type public.measurement_type NOT NULL, + measurement text NOT NULL +); + + +ALTER TABLE macrostrat.measurements OWNER TO postgres; + +-- +-- Name: TABLE measurements; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.measurements IS 'Last updated from MariaDB - 2022-02-25 15:08'; + + +-- +-- Name: measurements_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measurements_id_seq + START WITH 125 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measurements_id_seq OWNER TO postgres; + +-- +-- Name: measurements_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measurements_id_seq OWNED BY macrostrat.measurements.id; + + -- -- Name: measurements_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- @@ -833,6 +945,28 @@ CREATE SEQUENCE macrostrat.measurements_new_id_seq ALTER TABLE macrostrat.measurements_new_id_seq OWNER TO postgres; +-- +-- Name: measurements_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measurements_new_id_seq1 + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measurements_new_id_seq1 OWNER TO postgres; + +-- +-- Name: measurements_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measurements_new_id_seq1 OWNED BY macrostrat.measurements.id; + + -- -- Name: measuremeta; Type: TABLE; Schema: macrostrat; Owner: postgres -- @@ -861,7 +995,7 @@ ALTER TABLE macrostrat.measuremeta OWNER TO postgres; -- Name: TABLE measuremeta; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.measuremeta IS 'Last updated from MariaDB - 2021-08-30 11:27'; +COMMENT ON TABLE macrostrat.measuremeta IS 'Last updated from MariaDB - 2022-02-25 14:29'; -- @@ -886,10 +1020,10 @@ ALTER SEQUENCE macrostrat.measuremeta_id_seq OWNED BY macrostrat.measuremeta.id; -- --- Name: measuremeta_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- Name: measuremeta_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- -CREATE SEQUENCE macrostrat.measuremeta_new_id_seq1 +CREATE SEQUENCE macrostrat.measuremeta_new_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -898,13 +1032,13 @@ CREATE SEQUENCE macrostrat.measuremeta_new_id_seq1 CACHE 1; -ALTER TABLE macrostrat.measuremeta_new_id_seq1 OWNER TO postgres; +ALTER TABLE macrostrat.measuremeta_new_id_seq OWNER TO postgres; -- --- Name: measuremeta_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- Name: measuremeta_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres -- -ALTER SEQUENCE macrostrat.measuremeta_new_id_seq1 OWNED BY macrostrat.measuremeta.id; +ALTER SEQUENCE macrostrat.measuremeta_new_id_seq OWNED BY macrostrat.measuremeta.id; -- @@ -1014,7 +1148,7 @@ CREATE TABLE macrostrat.places ( postal text, country text, country_abbrev text, - geom public.geometry(Geometry,4326) + geom public.geometry ); @@ -1024,7 +1158,7 @@ ALTER TABLE macrostrat.places OWNER TO postgres; -- Name: TABLE places; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.places IS 'Last updated from MariaDB - 2021-08-30 11:59'; +COMMENT ON TABLE macrostrat.places IS 'Last updated from MariaDB - 2022-02-25 14:29'; -- @@ -1049,24 +1183,31 @@ ALTER SEQUENCE macrostrat.places_place_id_seq OWNED BY macrostrat.places.place_i -- --- Name: projects; Type: TABLE; Schema: macrostrat; Owner: postgres +-- Name: projects_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- -CREATE TABLE macrostrat.projects ( - id integer NOT NULL, - project text, - descrip text, - timescale_id integer -); +CREATE SEQUENCE macrostrat.projects_id_seq + START WITH 13 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; -ALTER TABLE macrostrat.projects OWNER TO postgres; +ALTER TABLE macrostrat.projects_id_seq OWNER TO postgres; -- --- Name: projects_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- Name: projects_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres -- -CREATE SEQUENCE macrostrat.projects_id_seq +ALTER SEQUENCE macrostrat.projects_id_seq OWNED BY macrostrat.projects.id; + + +-- +-- Name: projects_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.projects_new_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -1075,13 +1216,13 @@ CREATE SEQUENCE macrostrat.projects_id_seq CACHE 1; -ALTER TABLE macrostrat.projects_id_seq OWNER TO postgres; +ALTER TABLE macrostrat.projects_new_id_seq OWNER TO postgres; -- --- Name: projects_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- Name: projects_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres -- -ALTER SEQUENCE macrostrat.projects_id_seq OWNED BY macrostrat.projects.id; +ALTER SEQUENCE macrostrat.projects_new_id_seq OWNED BY macrostrat.projects.id; -- @@ -1130,6 +1271,68 @@ ALTER TABLE macrostrat.refs_id_seq OWNER TO postgres; ALTER SEQUENCE macrostrat.refs_id_seq OWNED BY macrostrat.refs.id; +-- +-- Name: sections; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.sections ( + id integer NOT NULL, + col_id integer +); + + +ALTER TABLE macrostrat.sections OWNER TO postgres; + +-- +-- Name: TABLE sections; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.sections IS 'Last updated from MariaDB - 2022-02-25 14:41'; + + +-- +-- Name: sections_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.sections_id_seq + START WITH 12737 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.sections_id_seq OWNER TO postgres; + +-- +-- Name: sections_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.sections_id_seq OWNED BY macrostrat.sections.id; + + +-- +-- Name: sections_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.sections_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.sections_new_id_seq OWNER TO postgres; + +-- +-- Name: sections_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.sections_new_id_seq OWNED BY macrostrat.sections.id; + + -- -- Name: strat_name_footprints; Type: TABLE; Schema: macrostrat; Owner: postgres -- @@ -1157,8 +1360,7 @@ CREATE TABLE macrostrat.strat_names ( strat_name character varying(100) NOT NULL, rank character varying(50), ref_id integer NOT NULL, - concept_id integer, - parent integer + concept_id integer ); @@ -1280,7 +1482,71 @@ ALTER TABLE macrostrat.strat_names_places OWNER TO postgres; -- Name: TABLE strat_names_places; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.strat_names_places IS 'Last updated from MariaDB - 2021-08-30 11:30'; +COMMENT ON TABLE macrostrat.strat_names_places IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: strat_tree; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_tree ( + id integer NOT NULL, + parent integer, + child integer, + ref_id integer +); + + +ALTER TABLE macrostrat.strat_tree OWNER TO postgres; + +-- +-- Name: TABLE strat_tree; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.strat_tree IS 'Last updated from MariaDB - 2022-02-25 14:40'; + + +-- +-- Name: strat_tree_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_tree_id_seq + START WITH 29785 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_tree_id_seq OWNER TO postgres; + +-- +-- Name: strat_tree_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_tree_id_seq OWNED BY macrostrat.strat_tree.id; + + +-- +-- Name: strat_tree_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_tree_new_id_seq1 + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_tree_new_id_seq1 OWNER TO postgres; + +-- +-- Name: strat_tree_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_tree_new_id_seq1 OWNED BY macrostrat.strat_tree.id; -- @@ -1340,7 +1606,7 @@ ALTER TABLE macrostrat.timescales_intervals OWNER TO postgres; -- Name: TABLE timescales_intervals; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.timescales_intervals IS 'Last updated from MariaDB - 2021-08-30 11:30'; +COMMENT ON TABLE macrostrat.timescales_intervals IS 'Last updated from MariaDB - 2022-02-25 14:29'; -- @@ -1413,7 +1679,7 @@ COMMENT ON TABLE macrostrat.unit_environs IS 'Last updated from MariaDB - 2021-0 -- CREATE SEQUENCE macrostrat.unit_environs_id_seq - START WITH 85929 + START WITH 85924 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -1496,7 +1762,7 @@ ALTER TABLE macrostrat.unit_liths OWNER TO postgres; -- Name: TABLE unit_liths; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.unit_liths IS 'Last updated from MariaDB - 2021-08-30 11:29'; +COMMENT ON TABLE macrostrat.unit_liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -1504,7 +1770,7 @@ COMMENT ON TABLE macrostrat.unit_liths IS 'Last updated from MariaDB - 2021-08-3 -- CREATE SEQUENCE macrostrat.unit_liths_id_seq - START WITH 130551 + START WITH 132637 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -1603,7 +1869,7 @@ ALTER TABLE macrostrat.unit_strat_names OWNER TO postgres; -- Name: TABLE unit_strat_names; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.unit_strat_names IS 'Last updated from MariaDB - 2021-08-30 11:25'; +COMMENT ON TABLE macrostrat.unit_strat_names IS 'Last updated from MariaDB - 2022-02-25 14:28'; -- @@ -1628,10 +1894,10 @@ ALTER SEQUENCE macrostrat.unit_strat_names_id_seq OWNED BY macrostrat.unit_strat -- --- Name: unit_strat_names_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- Name: unit_strat_names_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- -CREATE SEQUENCE macrostrat.unit_strat_names_new_id_seq1 +CREATE SEQUENCE macrostrat.unit_strat_names_new_id_seq AS integer START WITH 1 INCREMENT BY 1 @@ -1640,13 +1906,13 @@ CREATE SEQUENCE macrostrat.unit_strat_names_new_id_seq1 CACHE 1; -ALTER TABLE macrostrat.unit_strat_names_new_id_seq1 OWNER TO postgres; +ALTER TABLE macrostrat.unit_strat_names_new_id_seq OWNER TO postgres; -- --- Name: unit_strat_names_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- Name: unit_strat_names_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres -- -ALTER SEQUENCE macrostrat.unit_strat_names_new_id_seq1 OWNED BY macrostrat.unit_strat_names.id; +ALTER SEQUENCE macrostrat.unit_strat_names_new_id_seq OWNED BY macrostrat.unit_strat_names.id; -- @@ -1665,7 +1931,9 @@ CREATE TABLE macrostrat.units ( max_thick numeric, min_thick numeric, section_id integer, - col_id integer + col_id integer, + notes text, + strat_name_id integer ); @@ -1675,7 +1943,7 @@ ALTER TABLE macrostrat.units OWNER TO postgres; -- Name: TABLE units; Type: COMMENT; Schema: macrostrat; Owner: postgres -- -COMMENT ON TABLE macrostrat.units IS 'Last updated from MariaDB - 2021-08-30 11:31'; +COMMENT ON TABLE macrostrat.units IS 'Last updated from MariaDB - 2022-02-25 14:47'; -- @@ -1683,7 +1951,7 @@ COMMENT ON TABLE macrostrat.units IS 'Last updated from MariaDB - 2021-08-30 11: -- CREATE SEQUENCE macrostrat.units_id_seq - START WITH 52384 + START WITH 53232 INCREMENT BY 1 NO MINVALUE NO MAXVALUE @@ -1771,6 +2039,7 @@ CREATE VIEW macrostrat_api.col_form AS SELECT c.id AS col_id, c.col_name, c.col AS col_number, + c.notes, json_build_object('id', r.id, 'pub_year', r.pub_year, 'author', r.author, 'ref', r.ref, 'doi', r.doi, 'url', r.url) AS ref FROM ((macrostrat.cols c LEFT JOIN macrostrat.col_refs cr ON ((c.id = cr.col_id))) @@ -1860,7 +2129,8 @@ CREATE VIEW macrostrat_api.cols AS cols.coordinate, cols.wkt, cols.created, - cols.poly_geom + cols.poly_geom, + cols.notes FROM macrostrat.cols; @@ -2012,11 +2282,11 @@ ALTER TABLE macrostrat_api.liths OWNER TO postgres; -- CREATE VIEW macrostrat_api.projects AS - SELECT projects.id, - projects.project, - projects.descrip, - projects.timescale_id - FROM macrostrat.projects; + SELECT get_projects.id, + get_projects.project, + get_projects.descrip, + get_projects.timescale_id + FROM macrostrat_api.get_projects() get_projects(id, project, descrip, timescale_id); ALTER TABLE macrostrat_api.projects OWNER TO postgres; @@ -2039,24 +2309,63 @@ CREATE VIEW macrostrat_api.refs AS ALTER TABLE macrostrat_api.refs OWNER TO postgres; +-- +-- Name: sections; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- + +CREATE VIEW macrostrat_api.sections AS + SELECT sections.id, + sections.col_id + FROM macrostrat.sections; + + +ALTER TABLE macrostrat_api.sections OWNER TO postgres; + -- -- Name: strat_names; Type: VIEW; Schema: macrostrat_api; Owner: postgres -- CREATE VIEW macrostrat_api.strat_names AS + SELECT strat_names.id, + strat_names.strat_name, + strat_names.rank, + strat_names.ref_id, + strat_names.concept_id + FROM macrostrat.strat_names; + + +ALTER TABLE macrostrat_api.strat_names OWNER TO postgres; + +-- +-- Name: strat_names_view; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- + +CREATE VIEW macrostrat_api.strat_names_view AS SELECT s.id, s.strat_name, s.rank, row_to_json(r.*) AS ref, - row_to_json(sm.*) AS concept, - row_to_json(sn.*) AS parent - FROM (((macrostrat.strat_names s - LEFT JOIN macrostrat.strat_names sn ON ((s.parent = sn.id))) + row_to_json(sm.*) AS concept + FROM ((macrostrat.strat_names s LEFT JOIN macrostrat.refs r ON ((r.id = s.ref_id))) LEFT JOIN macrostrat.strat_names_meta sm ON ((sm.concept_id = s.concept_id))); -ALTER TABLE macrostrat_api.strat_names OWNER TO postgres; +ALTER TABLE macrostrat_api.strat_names_view OWNER TO postgres; + +-- +-- Name: strat_tree; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- + +CREATE VIEW macrostrat_api.strat_tree AS + SELECT strat_tree.id, + strat_tree.parent, + strat_tree.child, + strat_tree.ref_id + FROM macrostrat.strat_tree; + + +ALTER TABLE macrostrat_api.strat_tree OWNER TO postgres; -- -- Name: timescales; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2122,7 +2431,9 @@ CREATE VIEW macrostrat_api.units AS units.max_thick, units.min_thick, units.section_id, - units.col_id + units.col_id, + units.notes, + units.strat_name_id FROM macrostrat.units; @@ -2135,9 +2446,7 @@ ALTER TABLE macrostrat_api.units OWNER TO postgres; CREATE VIEW macrostrat_api.units_view AS SELECT u.id, u.strat_name AS unit_strat_name, - s.strat_name, - s.rank, - s.id AS strat_name_id, + to_jsonb(s.*) AS strat_name, u.color, u.outcrop, u.fo, @@ -2148,15 +2457,15 @@ CREATE VIEW macrostrat_api.units_view AS u.min_thick, u.section_id, u.col_id, + u.notes, fo.interval_name AS name_fo, fo.age_bottom, lo.interval_name AS name_lo, lo.age_top - FROM ((((macrostrat.units u + FROM (((macrostrat.units u LEFT JOIN macrostrat.intervals fo ON ((u.fo = fo.id))) LEFT JOIN macrostrat.intervals lo ON ((u.lo = lo.id))) - LEFT JOIN macrostrat.unit_strat_names usn ON ((usn.unit_id = u.id))) - LEFT JOIN macrostrat.strat_names s ON ((usn.strat_name_id = s.id))); + LEFT JOIN macrostrat.strat_names s ON ((u.strat_name_id = s.id))); ALTER TABLE macrostrat_api.units_view OWNER TO postgres; @@ -2238,6 +2547,13 @@ ALTER TABLE ONLY macrostrat.liths ALTER COLUMN id SET DEFAULT nextval('macrostra ALTER TABLE ONLY macrostrat.lookup_units ALTER COLUMN unit_id SET DEFAULT nextval('macrostrat.lookup_units_unit_id_seq'::regclass); +-- +-- Name: measurements id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measurements ALTER COLUMN id SET DEFAULT nextval('macrostrat.measurements_id_seq'::regclass); + + -- -- Name: measuremeta id; Type: DEFAULT; Schema: macrostrat; Owner: postgres -- @@ -2273,6 +2589,13 @@ ALTER TABLE ONLY macrostrat.projects ALTER COLUMN id SET DEFAULT nextval('macros ALTER TABLE ONLY macrostrat.refs ALTER COLUMN id SET DEFAULT nextval('macrostrat.refs_id_seq'::regclass); +-- +-- Name: sections id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections ALTER COLUMN id SET DEFAULT nextval('macrostrat.sections_id_seq'::regclass); + + -- -- Name: strat_names id; Type: DEFAULT; Schema: macrostrat; Owner: postgres -- @@ -2287,6 +2610,13 @@ ALTER TABLE ONLY macrostrat.strat_names ALTER COLUMN id SET DEFAULT nextval('mac ALTER TABLE ONLY macrostrat.strat_names_meta ALTER COLUMN concept_id SET DEFAULT nextval('macrostrat.strat_names_meta_concept_id_seq'::regclass); +-- +-- Name: strat_tree id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree ALTER COLUMN id SET DEFAULT nextval('macrostrat.strat_tree_id_seq'::regclass); + + -- -- Name: timescales id; Type: DEFAULT; Schema: macrostrat; Owner: postgres -- @@ -2367,11 +2697,11 @@ ALTER TABLE ONLY macrostrat.col_groups -- --- Name: col_refs col_refs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: col_refs col_refs_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.col_refs - ADD CONSTRAINT col_refs_new_pkey1 PRIMARY KEY (id); + ADD CONSTRAINT col_refs_new_pkey PRIMARY KEY (id); -- @@ -2383,11 +2713,11 @@ ALTER TABLE ONLY macrostrat.cols -- --- Name: econs econs_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: econs econs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.econs - ADD CONSTRAINT econs_new_pkey PRIMARY KEY (id); + ADD CONSTRAINT econs_new_pkey1 PRIMARY KEY (id); -- @@ -2423,11 +2753,11 @@ ALTER TABLE ONLY macrostrat.lith_atts -- --- Name: liths liths_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: liths liths_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.liths - ADD CONSTRAINT liths_new_pkey1 PRIMARY KEY (id); + ADD CONSTRAINT liths_new_pkey PRIMARY KEY (id); -- @@ -2439,27 +2769,35 @@ ALTER TABLE ONLY macrostrat.lookup_units -- --- Name: measuremeta measuremeta_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: measurements measurements_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measurements + ADD CONSTRAINT measurements_new_pkey PRIMARY KEY (id); + + +-- +-- Name: measuremeta measuremeta_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.measuremeta - ADD CONSTRAINT measuremeta_new_pkey PRIMARY KEY (id); + ADD CONSTRAINT measuremeta_new_pkey1 PRIMARY KEY (id); -- --- Name: places places_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: places places_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.places - ADD CONSTRAINT places_new_pkey1 PRIMARY KEY (place_id); + ADD CONSTRAINT places_new_pkey PRIMARY KEY (place_id); -- --- Name: projects projects_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: projects projects_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.projects - ADD CONSTRAINT projects_pkey PRIMARY KEY (id); + ADD CONSTRAINT projects_new_pkey PRIMARY KEY (id); -- @@ -2470,6 +2808,14 @@ ALTER TABLE ONLY macrostrat.refs ADD CONSTRAINT refs_new_pkey1 PRIMARY KEY (id); +-- +-- Name: sections sections_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_new_pkey PRIMARY KEY (id); + + -- -- Name: strat_names_meta strat_names_meta_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -2486,6 +2832,14 @@ ALTER TABLE ONLY macrostrat.strat_names ADD CONSTRAINT strat_names_new_pkey PRIMARY KEY (id); +-- +-- Name: strat_tree strat_tree_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_new_pkey1 PRIMARY KEY (id); + + -- -- Name: timescales timescales_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -2519,11 +2873,11 @@ ALTER TABLE ONLY macrostrat.unit_lith_atts -- --- Name: unit_liths unit_liths_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: unit_liths unit_liths_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.unit_liths - ADD CONSTRAINT unit_liths_new_pkey1 PRIMARY KEY (id); + ADD CONSTRAINT unit_liths_new_pkey PRIMARY KEY (id); -- @@ -2535,11 +2889,11 @@ ALTER TABLE ONLY macrostrat.unit_measures -- --- Name: unit_strat_names unit_strat_names_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: unit_strat_names unit_strat_names_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres -- ALTER TABLE ONLY macrostrat.unit_strat_names - ADD CONSTRAINT unit_strat_names_new_pkey1 PRIMARY KEY (id); + ADD CONSTRAINT unit_strat_names_new_pkey PRIMARY KEY (id); -- @@ -2559,31 +2913,31 @@ ALTER TABLE ONLY macrostrat.units_sections -- --- Name: autocomplete_new_category_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: autocomplete_new_category_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX autocomplete_new_category_idx1 ON macrostrat.autocomplete USING btree (category); +CREATE INDEX autocomplete_new_category_idx ON macrostrat.autocomplete USING btree (category); -- --- Name: autocomplete_new_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: autocomplete_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX autocomplete_new_id_idx1 ON macrostrat.autocomplete USING btree (id); +CREATE INDEX autocomplete_new_id_idx ON macrostrat.autocomplete USING btree (id); -- --- Name: autocomplete_new_name_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: autocomplete_new_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX autocomplete_new_name_idx1 ON macrostrat.autocomplete USING btree (name); +CREATE INDEX autocomplete_new_name_idx ON macrostrat.autocomplete USING btree (name); -- --- Name: autocomplete_new_type_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: autocomplete_new_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX autocomplete_new_type_idx1 ON macrostrat.autocomplete USING btree (type); +CREATE INDEX autocomplete_new_type_idx ON macrostrat.autocomplete USING btree (type); -- @@ -2608,17 +2962,17 @@ CREATE INDEX col_groups_new_id_idx1 ON macrostrat.col_groups USING btree (id); -- --- Name: col_refs_new_col_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: col_refs_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX col_refs_new_col_id_idx1 ON macrostrat.col_refs USING btree (col_id); +CREATE INDEX col_refs_new_col_id_idx ON macrostrat.col_refs USING btree (col_id); -- --- Name: col_refs_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: col_refs_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX col_refs_new_ref_id_idx1 ON macrostrat.col_refs USING btree (ref_id); +CREATE INDEX col_refs_new_ref_id_idx ON macrostrat.col_refs USING btree (ref_id); -- @@ -2671,38 +3025,38 @@ CREATE INDEX concepts_places_new_place_id_idx ON macrostrat.concepts_places USIN -- --- Name: intervals_new_age_bottom_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_age_bottom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX intervals_new_age_bottom_idx1 ON macrostrat.intervals USING btree (age_bottom); +CREATE INDEX intervals_new_age_bottom_idx ON macrostrat.intervals USING btree (age_bottom); -- --- Name: intervals_new_age_top_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_age_top_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX intervals_new_age_top_idx1 ON macrostrat.intervals USING btree (age_top); +CREATE INDEX intervals_new_age_top_idx ON macrostrat.intervals USING btree (age_top); -- --- Name: intervals_new_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX intervals_new_id_idx1 ON macrostrat.intervals USING btree (id); +CREATE INDEX intervals_new_id_idx ON macrostrat.intervals USING btree (id); -- --- Name: intervals_new_interval_name_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_interval_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX intervals_new_interval_name_idx1 ON macrostrat.intervals USING btree (interval_name); +CREATE INDEX intervals_new_interval_name_idx ON macrostrat.intervals USING btree (interval_name); -- --- Name: intervals_new_interval_type_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: intervals_new_interval_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX intervals_new_interval_type_idx1 ON macrostrat.intervals USING btree (interval_type); +CREATE INDEX intervals_new_interval_type_idx ON macrostrat.intervals USING btree (interval_type); -- @@ -2720,24 +3074,24 @@ CREATE INDEX lith_atts_new_lith_att_idx1 ON macrostrat.lith_atts USING btree (li -- --- Name: liths_new_lith_class_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: liths_new_lith_class_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX liths_new_lith_class_idx1 ON macrostrat.liths USING btree (lith_class); +CREATE INDEX liths_new_lith_class_idx ON macrostrat.liths USING btree (lith_class); -- --- Name: liths_new_lith_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: liths_new_lith_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX liths_new_lith_idx1 ON macrostrat.liths USING btree (lith); +CREATE INDEX liths_new_lith_idx ON macrostrat.liths USING btree (lith); -- --- Name: liths_new_lith_type_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: liths_new_lith_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX liths_new_lith_type_idx1 ON macrostrat.liths USING btree (lith_type); +CREATE INDEX liths_new_lith_type_idx ON macrostrat.liths USING btree (lith_type); -- @@ -2846,24 +3200,45 @@ CREATE INDEX lookup_units_new_t_int_idx1 ON macrostrat.lookup_units USING btree -- --- Name: measuremeta_new_lith_att_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: measurements_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_id_idx ON macrostrat.measurements USING btree (id); + + +-- +-- Name: measurements_new_measurement_class_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_measurement_class_idx ON macrostrat.measurements USING btree (measurement_class); + + +-- +-- Name: measurements_new_measurement_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_measurement_type_idx ON macrostrat.measurements USING btree (measurement_type); + + +-- +-- Name: measuremeta_new_lith_att_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX measuremeta_new_lith_att_id_idx1 ON macrostrat.measuremeta USING btree (lith_att_id); +CREATE INDEX measuremeta_new_lith_att_id_idx ON macrostrat.measuremeta USING btree (lith_att_id); -- --- Name: measuremeta_new_lith_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: measuremeta_new_lith_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX measuremeta_new_lith_id_idx1 ON macrostrat.measuremeta USING btree (lith_id); +CREATE INDEX measuremeta_new_lith_id_idx ON macrostrat.measuremeta USING btree (lith_id); -- --- Name: measuremeta_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: measuremeta_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX measuremeta_new_ref_id_idx1 ON macrostrat.measuremeta USING btree (ref_id); +CREATE INDEX measuremeta_new_ref_id_idx ON macrostrat.measuremeta USING btree (ref_id); -- @@ -2909,10 +3284,24 @@ CREATE INDEX pbdb_collections_new_late_age_idx ON macrostrat.pbdb_collections US -- --- Name: places_new_geom_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: places_new_geom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX places_new_geom_idx1 ON macrostrat.places USING gist (geom); +CREATE INDEX places_new_geom_idx ON macrostrat.places USING gist (geom); + + +-- +-- Name: projects_new_project_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX projects_new_project_idx ON macrostrat.projects USING btree (project); + + +-- +-- Name: projects_new_timescale_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX projects_new_timescale_id_idx ON macrostrat.projects USING btree (timescale_id); -- @@ -2922,6 +3311,20 @@ CREATE INDEX places_new_geom_idx1 ON macrostrat.places USING gist (geom); CREATE INDEX refs_new_rgeom_idx1 ON macrostrat.refs USING gist (rgeom); +-- +-- Name: sections_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX sections_new_col_id_idx ON macrostrat.sections USING btree (col_id); + + +-- +-- Name: sections_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX sections_new_id_idx ON macrostrat.sections USING btree (id); + + -- -- Name: strat_name_footprints_new_geom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- @@ -2993,31 +3396,52 @@ CREATE INDEX strat_names_new_strat_name_idx ON macrostrat.strat_names USING btre -- --- Name: strat_names_places_new_place_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: strat_names_places_new_place_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX strat_names_places_new_place_id_idx1 ON macrostrat.strat_names_places USING btree (place_id); +CREATE INDEX strat_names_places_new_place_id_idx ON macrostrat.strat_names_places USING btree (place_id); -- --- Name: strat_names_places_new_strat_name_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: strat_names_places_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX strat_names_places_new_strat_name_id_idx1 ON macrostrat.strat_names_places USING btree (strat_name_id); +CREATE INDEX strat_names_places_new_strat_name_id_idx ON macrostrat.strat_names_places USING btree (strat_name_id); -- --- Name: timescales_intervals_new_interval_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: strat_tree_new_child_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX timescales_intervals_new_interval_id_idx1 ON macrostrat.timescales_intervals USING btree (interval_id); +CREATE INDEX strat_tree_new_child_idx1 ON macrostrat.strat_tree USING btree (child); -- --- Name: timescales_intervals_new_timescale_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: strat_tree_new_parent_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX timescales_intervals_new_timescale_id_idx1 ON macrostrat.timescales_intervals USING btree (timescale_id); +CREATE INDEX strat_tree_new_parent_idx1 ON macrostrat.strat_tree USING btree (parent); + + +-- +-- Name: strat_tree_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_tree_new_ref_id_idx1 ON macrostrat.strat_tree USING btree (ref_id); + + +-- +-- Name: timescales_intervals_new_interval_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_intervals_new_interval_id_idx ON macrostrat.timescales_intervals USING btree (interval_id); + + +-- +-- Name: timescales_intervals_new_timescale_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_intervals_new_timescale_id_idx ON macrostrat.timescales_intervals USING btree (timescale_id); -- @@ -3098,24 +3522,24 @@ CREATE INDEX unit_lith_atts_new_unit_lith_id_idx1 ON macrostrat.unit_lith_atts U -- --- Name: unit_liths_new_lith_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: unit_liths_new_lith_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX unit_liths_new_lith_id_idx1 ON macrostrat.unit_liths USING btree (lith_id); +CREATE INDEX unit_liths_new_lith_id_idx ON macrostrat.unit_liths USING btree (lith_id); -- --- Name: unit_liths_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: unit_liths_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX unit_liths_new_ref_id_idx1 ON macrostrat.unit_liths USING btree (ref_id); +CREATE INDEX unit_liths_new_ref_id_idx ON macrostrat.unit_liths USING btree (ref_id); -- --- Name: unit_liths_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: unit_liths_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX unit_liths_new_unit_id_idx1 ON macrostrat.unit_liths USING btree (unit_id); +CREATE INDEX unit_liths_new_unit_id_idx ON macrostrat.unit_liths USING btree (unit_id); -- @@ -3140,17 +3564,17 @@ CREATE INDEX unit_measures_new_unit_id_idx ON macrostrat.unit_measures USING btr -- --- Name: unit_strat_names_new_strat_name_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: unit_strat_names_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX unit_strat_names_new_strat_name_id_idx1 ON macrostrat.unit_strat_names USING btree (strat_name_id); +CREATE INDEX unit_strat_names_new_strat_name_id_idx ON macrostrat.unit_strat_names USING btree (strat_name_id); -- --- Name: unit_strat_names_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- Name: unit_strat_names_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres -- -CREATE INDEX unit_strat_names_new_unit_id_idx1 ON macrostrat.unit_strat_names USING btree (unit_id); +CREATE INDEX unit_strat_names_new_unit_id_idx ON macrostrat.unit_strat_names USING btree (unit_id); -- @@ -3278,15 +3702,15 @@ ALTER TABLE ONLY macrostrat.concepts_places -- ALTER TABLE ONLY macrostrat.projects - ADD CONSTRAINT projects_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id); + ADD CONSTRAINT projects_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; -- --- Name: strat_names strat_names_parent_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- Name: sections sections_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- -ALTER TABLE ONLY macrostrat.strat_names - ADD CONSTRAINT strat_names_parent_fkey FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id); +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; -- @@ -3305,6 +3729,30 @@ ALTER TABLE ONLY macrostrat.strat_names_places ADD CONSTRAINT strat_names_places_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: strat_tree strat_tree_child_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_child_fkey FOREIGN KEY (child) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_parent_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_parent_fkey FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + -- -- Name: timescales_intervals timescales_intervals_interval_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3441,6 +3889,22 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_lo_fkey FOREIGN KEY (lo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; +-- +-- Name: units units_section_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_section_id_fkey FOREIGN KEY (section_id) REFERENCES macrostrat.sections(id) ON DELETE CASCADE; + + +-- +-- Name: units units_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + -- -- PostgreSQL database dump complete -- diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_inserts.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_inserts.sql index 60bf685a0..82cb9c49c 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_inserts.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_inserts.sql @@ -366,6 +366,43 @@ VALUES (141,1,1,E'column',E'active',E'',17,E'Potomac Estuary',38.45,-76.729,4441.5,E'0101000020E61000002DB29DEFA72E53C09A99999999394340',E'POINT(-76.729 38.45)',NULL,E'0103000020E61000000100000006000000E25A101C644853C0A5D8D7D0693343403C110B88123853C01BE801CA366F43404A0E5E4D420A53C010EDCC17715043406FEDAC7DA70453C013BE3F22822C4340178D12EAEC3953C02906359739164340E25A101C644853C0A5D8D7D069334340'), (112,1,1,E'column',E'active',E'',19,E'Northern Coastal Plain',38.766,-77.308,3616.431,E'0101000020E6100000C1CAA145B65353C0355EBA490C624340',E'POINT(-77.308 38.766)',NULL,E'0103000020E61000000100000008000000B60914F84E6553C0F5F79A51536D43404377082BFF6053C0B7E1A9C7828E4340441DFF7B0B4253C046471DBFF390434040088ED8FC3D53C0CBEA7D8F7A8A43403C110B88123853C01BE801CA366F4340E25A101C644853C0A5D8D7D069334340992CBF18DB5453C0EAAEF55E582F4340B60914F84E6553C0F5F79A51536D4340'); +INSERT INTO "macrostrat"."sections"("id","col_id") +VALUES +(871,112), +(872,112), +(873,112), +(874,112), +(875,112), +(876,112), +(877,112), +(878,112), +(879,112), +(880,112), +(881,112), +(883,112), +(884,112), +(1037,125), +(1038,125), +(1039,125), +(1040,125), +(1041,125), +(1042,125), +(1043,125), +(1044,125), +(1045,125), +(1046,125), +(1047,125), +(1048,125), +(1049,125), +(1165,141), +(1166,141), +(1167,141), +(1168,141), +(1169,141), +(1170,141), +(1171,141), +(1172,141), +(1173,141); INSERT INTO "macrostrat"."units"("id","strat_name","color","outcrop","fo","lo","position_bottom","position_top","max_thick","min_thick","section_id","col_id") VALUES diff --git a/v2-transition/services/column-builder/database/fixtures/01-views.sql b/v2-transition/services/column-builder/database/fixtures/01-views.sql index 26862099d..96ed0aec0 100644 --- a/v2-transition/services/column-builder/database/fixtures/01-views.sql +++ b/v2-transition/services/column-builder/database/fixtures/01-views.sql @@ -2,8 +2,15 @@ CREATE SCHEMA IF NOT EXISTS macrostrat_api; +CREATE OR REPLACE FUNCTION +macrostrat_api.get_projects() RETURNS SETOF macrostrat.projects AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.projects; +END +$$ language plpgsql SECURITY INVOKER; + CREATE OR REPLACE VIEW macrostrat_api.projects AS -SELECT * FROM macrostrat.projects; +SELECT * FROM macrostrat_api.get_projects(); CREATE OR REPLACE VIEW macrostrat_api.cols AS SELECT * FROM macrostrat.cols; diff --git a/v2-transition/services/column-builder/docker-compose.yaml b/v2-transition/services/column-builder/docker-compose.yaml index d45c1c231..8c1d06ffc 100644 --- a/v2-transition/services/column-builder/docker-compose.yaml +++ b/v2-transition/services/column-builder/docker-compose.yaml @@ -15,6 +15,7 @@ services: environment: PGRST_DB_URI: postgres://${PGUSER}:@db:5432/${POSTGRES_DB} PGRST_DB_SCHEMA: macrostrat_api + PGRST_JWT_SECRET: ${PGRST_JWT_SECRET} PGRST_DB_ANON_ROLE: ${PGUSER} #In production this role should not be the same as the one used for the connection PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3001 depends_on: From 0d7ac0295ad30a5ea42c2b2f0af710c7bee36266 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Wed, 2 Mar 2022 20:22:30 +0100 Subject: [PATCH 02/13] auth views --- .../backend/tests/test_z_auth.py | 21 ++- .../urvogel/database/fixtures/auth.sql | 55 +++++- .../database/fixtures/01-views.sql | 156 +++++++++++++++--- .../column-builder/docker-compose.yaml | 14 +- 4 files changed, 204 insertions(+), 42 deletions(-) diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index be37c60ba..498d9eb2e 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -10,6 +10,13 @@ email = "cidzikowski@wisc.edu" password = "gniessrocks" +def login(): + res = post(base+"/rpc/login", data={"email": email, "pass": password}) + token = res.json().get('token') + headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} + + return headers + def test_create_auth(db): with db.conn.cursor() as cur: cur.execute(auth) @@ -94,14 +101,24 @@ def test_project_create(db): assert token is not None headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} - ## Can't insert into the view bc it was created from a function! res = post(base + "/projects", headers=headers, data={"project":"CFP1", "descrip":"fake project owned by casey", "timescale_id": 1}) - assert res.status_code == 200 + assert res.status_code == 201 res = get(base + "/projects", headers=headers) data = res.json() assert len(data) == 2 +def test_child_data(db): + """ add some col-group, col and unit and see that we can access it """ + headers = login() + + col_group = {"col_group": "CG1", "col_group_long": "Casey's first fake column group", "project_id":13} + res = post(base+"/col_groups", data=col_group, headers=headers) + + assert res.status_code == 201 + + res = get(base + "/col_groups", headers=headers) + assert len(res.json()) == 1 diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index 8bb199ef3..f77cbbfb0 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -173,7 +173,7 @@ DECLARE _role name; BEGIN INSERT INTO auth.users(email, pass, role) - VALUES (email, public.crypt(pass, public.gen_salt('md5')), 'new_user'); + VALUES (email, pass, 'new_user'); SELECT auth.user_role(email, pass) INTO _role; IF _role IS NULL THEN @@ -231,6 +231,9 @@ GRANT USAGE ON SCHEMA macrostrat TO new_user; GRANT USAGE ON SCHEMA auth TO new_user; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO new_user; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO new_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO new_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO new_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO new_user; GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO new_user; /* ################### Row level policies ################### */ @@ -250,25 +253,24 @@ CREATE OR REPLACE FUNCTION auth.user_project_insert() RETURNS trigger AS $$ DECLARE email_ text; - id_ + id_ int; BEGIN IF tg_op = 'INSERT' THEN select macrostrat_api.get_email() into email_; select id from auth.users where users.email = email_ INTO id_; - INSERT INTO auth.user_pojects(user, project, role_) - VALUES(id_, new.id, "owner_"); + INSERT INTO auth.user_projects(user_, project, role) + VALUES(id_, new.id, 'owner_'); END IF; RETURN new; END $$ LANGUAGE plpgsql; -DROP trigger IF EXISTS encrypt_pass ON auth.users; +DROP trigger IF EXISTS user_pojects ON macrostrat.projects; CREATE trigger user_pojects AFTER INSERT ON macrostrat.projects FOR EACH ROW EXECUTE PROCEDURE auth.user_project_insert(); - CREATE OR REPLACE FUNCTION macrostrat_api.current_user_projects() RETURNS TABLE(id int) AS $$ DECLARE @@ -282,7 +284,46 @@ BEGIN END $$ language plpgsql SECURITY DEFINER; + +/* projects */ ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; CREATE POLICY projects_ ON macrostrat.projects FOR SELECT -USING (id IN (SELECT macrostrat_api.current_user_projects())); \ No newline at end of file +USING (id IN (SELECT macrostrat_api.current_user_projects())); + +CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT +WITH CHECK(TRUE); + +CREATE OR REPLACE FUNCTION macrostrat_api.project_insert() +RETURNS trigger AS $$ +BEGIN +INSERT INTO macrostrat.projects(project, descrip, timescale_id)VALUES + (NEW.project, NEW.descrip, NEW.timescale_id); +RETURN NEW; +END +$$ language plpgsql; + +CREATE trigger project_instead_insert + INSTEAD OF INSERT ON macrostrat_api.projects + FOR EACH ROW EXECUTE PROCEDURE macrostrat_api.project_insert(); + +/* col-groups */ +ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; + +CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT +USING (project_id IN (SELECT macrostrat_api.current_user_projects())); + +/* cols */ +ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; + +CREATE POLICY cols_select ON macrostrat.cols FOR SELECT +USING (project_id IN (SELECT macrostrat_api.current_user_projects())); + +/* units */ +ALTER TABLE macrostrat.units ENABLE ROW LEVEL SECURITY; + +CREATE POLICY units_select ON macrostrat.units FOR SELECT +USING (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT macrostrat_api.current_user_projects()))); diff --git a/v2-transition/services/column-builder/database/fixtures/01-views.sql b/v2-transition/services/column-builder/database/fixtures/01-views.sql index 96ed0aec0..516919894 100644 --- a/v2-transition/services/column-builder/database/fixtures/01-views.sql +++ b/v2-transition/services/column-builder/database/fixtures/01-views.sql @@ -12,60 +12,164 @@ $$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.projects AS SELECT * FROM macrostrat_api.get_projects(); +CREATE OR REPLACE FUNCTION +macrostrat_api.get_cols() RETURNS SETOF macrostrat.cols AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.cols; +END +$$ language plpgsql SECURITY INVOKER; + CREATE OR REPLACE VIEW macrostrat_api.cols AS -SELECT * FROM macrostrat.cols; +SELECT * FROM macrostrat_api.get_cols(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_col_groups() RETURNS SETOF macrostrat.col_groups AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.col_groups; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.col_groups AS -SELECT * FROM macrostrat.col_groups; +SELECT * FROM macrostrat_api.get_col_groups(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_envs() RETURNS SETOF macrostrat.environs AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.environs; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.environs AS -SELECT * FROM macrostrat.environs; +SELECT * FROM macrostrat_api.get_envs(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_liths() RETURNS SETOF macrostrat.liths AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.liths; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.liths AS -SELECT * FROM macrostrat.liths; +SELECT * FROM macrostrat_api.get_liths(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_intervals() RETURNS SETOF macrostrat.intervals AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.intervals; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.intervals AS -SELECT * FROM macrostrat.intervals; +SELECT * FROM macrostrat_api.get_intervals(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_timescales() RETURNS SETOF macrostrat.timescales AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.timescales; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.timescales AS -SELECT * FROM macrostrat.timescales; +SELECT * FROM macrostrat_api.get_timescales(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_strat_tree() RETURNS SETOF macrostrat.strat_tree AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.strat_tree; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.strat_tree AS -SELECT * FROM macrostrat.strat_tree; +SELECT * FROM macrostrat_api.get_strat_tree(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_refs() RETURNS SETOF macrostrat.refs AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.refs; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.refs AS -SELECT * FROM macrostrat.refs; +SELECT * FROM macrostrat_api.get_refs(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_units() RETURNS SETOF macrostrat.units AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.units; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.units AS -SELECT * FROM macrostrat.units; +SELECT * FROM macrostrat_api.get_units(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_col_refs() RETURNS SETOF macrostrat.col_refs AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.col_refs; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.col_refs AS -SELECT * FROM macrostrat.col_refs; +SELECT * FROM macrostrat_api.get_col_refs(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_unit_environs() RETURNS SETOF macrostrat.unit_environs AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.unit_environs; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.unit_environs AS -SELECT * FROM macrostrat.unit_environs; +SELECT * FROM macrostrat_api.get_unit_environs(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_unit_liths() RETURNS SETOF macrostrat.unit_liths AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.unit_liths; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.unit_liths AS -SELECT * FROM macrostrat.unit_liths; +SELECT * FROM macrostrat_api.get_unit_liths(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_sections() RETURNS SETOF macrostrat.sections AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.sections; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.sections AS -SELECT * FROM macrostrat.sections; +SELECT * FROM macrostrat_api.get_sections(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.get_strat_names() RETURNS SETOF macrostrat.strat_names AS $$ +BEGIN + RETURN QUERY SELECT * FROM macrostrat.strat_names; +END +$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.strat_names AS -SELECT * FROM macrostrat.strat_names; +SELECT * FROM macrostrat_api.get_strat_names(); -CREATE OR REPLACE VIEW macrostrat_api.strat_names_view AS -SELECT -s.id, -s.strat_name, -s.rank, -row_to_json(r.*) ref, -row_to_json(sm.*) concept -FROM macrostrat.strat_names s -LEFT JOIN macrostrat.refs r -ON r.id = s.ref_id -LEFT JOIN macrostrat.strat_names_meta sm -ON sm.concept_id = s.concept_id; +CREATE OR REPLACE FUNCTION +macrostrat_api.get_strat_names_view() RETURNS VOID AS $$ +BEGIN + CREATE VIEW macrostrat_api.strat_names_view AS SELECT + s.id, + s.strat_name, + s.rank, + row_to_json(r.*) ref, + row_to_json(sm.*) concept + FROM macrostrat.strat_names s + LEFT JOIN macrostrat.refs r + ON r.id = s.ref_id + LEFT JOIN macrostrat.strat_names_meta sm + ON sm.concept_id = s.concept_id; +END +$$ language plpgsql SECURITY INVOKER; + +SELECT macrostrat_api.get_strat_names_view(); CREATE OR REPLACE VIEW macrostrat_api.col_group_view AS SELECT cg.id, diff --git a/v2-transition/services/column-builder/docker-compose.yaml b/v2-transition/services/column-builder/docker-compose.yaml index 8c1d06ffc..8771b495c 100644 --- a/v2-transition/services/column-builder/docker-compose.yaml +++ b/v2-transition/services/column-builder/docker-compose.yaml @@ -31,13 +31,13 @@ services: - ${PG_PORT}:5432 volumes: - db_cluster:/var/lib/postgresql/data - dacite: - build: ./frontend/dacite - ports: - - 1234:1234 - volumes: - - ./frontend/dacite:/app/dacite - - /app/dacite/node_modules + # dacite: + # build: ./frontend/dacite + # ports: + # - 1234:1234 + # volumes: + # - ./frontend/dacite:/app/dacite + # - /app/dacite/node_modules # db_backup: # image: ghcr.io/uw-macrostrat/pg-backup-service:latest # environment: From 22485c40cc398ed3d4ff7b3163ba5df4c123fe1c Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Thu, 3 Mar 2022 21:24:24 +0100 Subject: [PATCH 03/13] more auth stuff --- .../column-builder/backend/bin/run-tests | 2 +- ...est_postgrest.py => arc-test_postgrest.py} | 0 .../backend/tests/test_z_auth.py | 8 +- .../urvogel/database/fixtures/auth.sql | 47 +- .../urvogel/database/fixtures/schema_dump.sql | 1057 +++++++++++++++-- .../database/fixtures/01-views.sql | 192 +-- 6 files changed, 1066 insertions(+), 240 deletions(-) rename v2-transition/services/column-builder/backend/tests/{test_postgrest.py => arc-test_postgrest.py} (100%) diff --git a/v2-transition/services/column-builder/backend/bin/run-tests b/v2-transition/services/column-builder/backend/bin/run-tests index 9fc334812..d8d144706 100755 --- a/v2-transition/services/column-builder/backend/bin/run-tests +++ b/v2-transition/services/column-builder/backend/bin/run-tests @@ -11,7 +11,7 @@ if [[ -n "$result" ]]; then POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon docker-compose up -d --build postgrest else echo "Starting Docker" - POSTGRES_DB=col_test docker-compose up -d + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon docker-compose up -d fi pytest --pdb diff --git a/v2-transition/services/column-builder/backend/tests/test_postgrest.py b/v2-transition/services/column-builder/backend/tests/arc-test_postgrest.py similarity index 100% rename from v2-transition/services/column-builder/backend/tests/test_postgrest.py rename to v2-transition/services/column-builder/backend/tests/arc-test_postgrest.py diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 498d9eb2e..37f6ea159 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -36,7 +36,7 @@ def test_create_auth(db): res = db.query(sql).fetchall() for row in res: - assert row.get('rolname') in ['reader', 'writer', 'deleter', 'owner_','anon','authenticator', 'new_user'] + assert row.get('rolname') in ['api_views_owner','reader', 'writer', 'deleter', 'owner_','anon','authenticator', 'new_user'] def test_pg_extensions(db): sql = """ select extname from pg_extension; """ @@ -78,8 +78,8 @@ def test_login(db): assert len(data) == 0 # make the user an owner - sql = """ insert into auth.user_projects(user_, project, role) - values(1, 1, 'owner_') """ + sql = """ insert into auth.user_projects(user_, project, can_upsert, can_delete) + values(1, 1, FALSE, FALSE) """ with db.conn.cursor() as cur: cur.execute(sql) @@ -120,5 +120,3 @@ def test_child_data(db): res = get(base + "/col_groups", headers=headers) assert len(res.json()) == 1 - - diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index f77cbbfb0..72f3a4d45 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -81,7 +81,8 @@ auth.user_projects( id serial primary key, user_ int REFERENCES auth.users(id), project int REFERENCES macrostrat.projects(id), - role name not null check (length(role) < 512) + can_upsert BOOLEAN, -- both insert and update + can_delete BOOLEAN -- can delete ); /* make sure the role being added to user table actually exists!! */ @@ -238,6 +239,7 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO new_user; /* ################### Row level policies ################### */ + /* function to get email off of jwt claims*/ CREATE OR REPLACE FUNCTION macrostrat_api.get_email() returns text AS $$ @@ -258,27 +260,27 @@ BEGIN IF tg_op = 'INSERT' THEN select macrostrat_api.get_email() into email_; select id from auth.users where users.email = email_ INTO id_; - INSERT INTO auth.user_projects(user_, project, role) - VALUES(id_, new.id, 'owner_'); + INSERT INTO auth.user_projects(user_, project, can_upsert, can_delete) + VALUES(id_, new.id, TRUE, TRUE); END IF; RETURN new; END $$ LANGUAGE plpgsql; -DROP trigger IF EXISTS user_pojects ON macrostrat.projects; -CREATE trigger user_pojects +DROP trigger IF EXISTS user_projects ON macrostrat.projects; +CREATE trigger user_projects AFTER INSERT ON macrostrat.projects FOR EACH ROW EXECUTE PROCEDURE auth.user_project_insert(); CREATE OR REPLACE FUNCTION -macrostrat_api.current_user_projects() RETURNS TABLE(id int) AS $$ +macrostrat_api.current_user_projects() RETURNS SETOF auth.user_projects AS $$ DECLARE email_ text; BEGIN SELECT macrostrat_api.get_email() INTO email_; RETURN QUERY - SELECT project FROM auth.user_projects + SELECT up.* FROM auth.user_projects up JOIN auth.users u on u.email = email_; END @@ -289,35 +291,34 @@ $$ language plpgsql SECURITY DEFINER; ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; CREATE POLICY projects_ ON macrostrat.projects FOR SELECT -USING (id IN (SELECT macrostrat_api.current_user_projects())); +USING (id IN (SELECT project FROM macrostrat_api.current_user_projects())); CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT WITH CHECK(TRUE); -CREATE OR REPLACE FUNCTION macrostrat_api.project_insert() -RETURNS trigger AS $$ -BEGIN -INSERT INTO macrostrat.projects(project, descrip, timescale_id)VALUES - (NEW.project, NEW.descrip, NEW.timescale_id); -RETURN NEW; -END -$$ language plpgsql; - -CREATE trigger project_instead_insert - INSTEAD OF INSERT ON macrostrat_api.projects - FOR EACH ROW EXECUTE PROCEDURE macrostrat_api.project_insert(); +CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE +WITH CHECK (TRUE); +-- id in ( +-- SELECT project FROM macrostrat_api.current_user_projects() +-- WHERE can_upsert IS TRUE +-- ) /* col-groups */ ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT -USING (project_id IN (SELECT macrostrat_api.current_user_projects())); +USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); + +CREATE POLICY col_group_upsert ON macrostrat.col_groups +WITH CHECK(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE can_upsert IS TRUE)); /* cols */ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; CREATE POLICY cols_select ON macrostrat.cols FOR SELECT -USING (project_id IN (SELECT macrostrat_api.current_user_projects())); +USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); /* units */ ALTER TABLE macrostrat.units ENABLE ROW LEVEL SECURITY; @@ -326,4 +327,4 @@ CREATE POLICY units_select ON macrostrat.units FOR SELECT USING (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN( - SELECT macrostrat_api.current_user_projects()))); + SELECT project FROM macrostrat_api.current_user_projects()))); diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql index f6aee4b65..e8fa65614 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/schema_dump.sql @@ -148,45 +148,26 @@ $_$; ALTER PROCEDURE macrostrat.pg_reset_pkey_seq() OWNER TO postgres; -SET default_tablespace = ''; - -SET default_table_access_method = heap; - --- --- Name: projects; Type: TABLE; Schema: macrostrat; Owner: postgres --- - -CREATE TABLE macrostrat.projects ( - id integer NOT NULL, - project text, - descrip text, - timescale_id integer -); - - -ALTER TABLE macrostrat.projects OWNER TO postgres; - --- --- Name: TABLE projects; Type: COMMENT; Schema: macrostrat; Owner: postgres --- - -COMMENT ON TABLE macrostrat.projects IS 'Last updated from MariaDB - 2022-02-25 14:40'; - - -- --- Name: get_projects(); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- Name: project_insert(); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres -- -CREATE FUNCTION macrostrat_api.get_projects() RETURNS SETOF macrostrat.projects +CREATE FUNCTION macrostrat_api.project_insert() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN - RETURN QUERY SELECT * FROM macrostrat.projects; -END +INSERT INTO macrostrat.projects(project, descrip, timescale_id)VALUES + (NEW.project, NEW.descrip, NEW.timescale_id); +RETURN NEW; +END $$; -ALTER FUNCTION macrostrat_api.get_projects() OWNER TO postgres; +ALTER FUNCTION macrostrat_api.project_insert() OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; -- -- Name: autocomplete; Type: TABLE; Schema: macrostrat; Owner: postgres @@ -1182,6 +1163,27 @@ ALTER TABLE macrostrat.places_place_id_seq OWNER TO postgres; ALTER SEQUENCE macrostrat.places_place_id_seq OWNED BY macrostrat.places.place_id; +-- +-- Name: projects; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.projects ( + id integer NOT NULL, + project text, + descrip text, + timescale_id integer +); + + +ALTER TABLE macrostrat.projects OWNER TO postgres; + +-- +-- Name: TABLE projects; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.projects IS 'Last updated from MariaDB - 2022-02-25 14:40'; + + -- -- Name: projects_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres -- @@ -2064,7 +2066,7 @@ SELECT ALTER TABLE macrostrat_api.col_group_view OWNER TO postgres; -- --- Name: col_groups; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: col_groups; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.col_groups AS @@ -2075,10 +2077,10 @@ CREATE VIEW macrostrat_api.col_groups AS FROM macrostrat.col_groups; -ALTER TABLE macrostrat_api.col_groups OWNER TO postgres; +ALTER TABLE macrostrat_api.col_groups OWNER TO api_views_owner; -- --- Name: col_refs; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: col_refs; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.col_refs AS @@ -2088,7 +2090,7 @@ CREATE VIEW macrostrat_api.col_refs AS FROM macrostrat.col_refs; -ALTER TABLE macrostrat_api.col_refs OWNER TO postgres; +ALTER TABLE macrostrat_api.col_refs OWNER TO api_views_owner; -- -- Name: col_sections; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2111,7 +2113,7 @@ CREATE VIEW macrostrat_api.col_sections AS ALTER TABLE macrostrat_api.col_sections OWNER TO postgres; -- --- Name: cols; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: cols; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.cols AS @@ -2134,7 +2136,7 @@ CREATE VIEW macrostrat_api.cols AS FROM macrostrat.cols; -ALTER TABLE macrostrat_api.cols OWNER TO postgres; +ALTER TABLE macrostrat_api.cols OWNER TO api_views_owner; -- -- Name: econ_unit; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2173,7 +2175,7 @@ CREATE VIEW macrostrat_api.environ_unit AS ALTER TABLE macrostrat_api.environ_unit OWNER TO postgres; -- --- Name: environs; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: environs; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.environs AS @@ -2185,10 +2187,10 @@ CREATE VIEW macrostrat_api.environs AS FROM macrostrat.environs; -ALTER TABLE macrostrat_api.environs OWNER TO postgres; +ALTER TABLE macrostrat_api.environs OWNER TO api_views_owner; -- --- Name: intervals; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: intervals; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.intervals AS @@ -2203,7 +2205,7 @@ CREATE VIEW macrostrat_api.intervals AS FROM macrostrat.intervals; -ALTER TABLE macrostrat_api.intervals OWNER TO postgres; +ALTER TABLE macrostrat_api.intervals OWNER TO api_views_owner; -- -- Name: lith_attr_unit; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2257,7 +2259,7 @@ CREATE VIEW macrostrat_api.lith_unit AS ALTER TABLE macrostrat_api.lith_unit OWNER TO postgres; -- --- Name: liths; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: liths; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.liths AS @@ -2275,24 +2277,24 @@ CREATE VIEW macrostrat_api.liths AS FROM macrostrat.liths; -ALTER TABLE macrostrat_api.liths OWNER TO postgres; +ALTER TABLE macrostrat_api.liths OWNER TO api_views_owner; -- --- Name: projects; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: projects; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.projects AS - SELECT get_projects.id, - get_projects.project, - get_projects.descrip, - get_projects.timescale_id - FROM macrostrat_api.get_projects() get_projects(id, project, descrip, timescale_id); + SELECT projects.id, + projects.project, + projects.descrip, + projects.timescale_id + FROM macrostrat.projects; -ALTER TABLE macrostrat_api.projects OWNER TO postgres; +ALTER TABLE macrostrat_api.projects OWNER TO api_views_owner; -- --- Name: refs; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: refs; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.refs AS @@ -2307,7 +2309,7 @@ CREATE VIEW macrostrat_api.refs AS FROM macrostrat.refs; -ALTER TABLE macrostrat_api.refs OWNER TO postgres; +ALTER TABLE macrostrat_api.refs OWNER TO api_views_owner; -- -- Name: sections; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2326,21 +2328,6 @@ ALTER TABLE macrostrat_api.sections OWNER TO postgres; -- CREATE VIEW macrostrat_api.strat_names AS - SELECT strat_names.id, - strat_names.strat_name, - strat_names.rank, - strat_names.ref_id, - strat_names.concept_id - FROM macrostrat.strat_names; - - -ALTER TABLE macrostrat_api.strat_names OWNER TO postgres; - --- --- Name: strat_names_view; Type: VIEW; Schema: macrostrat_api; Owner: postgres --- - -CREATE VIEW macrostrat_api.strat_names_view AS SELECT s.id, s.strat_name, s.rank, @@ -2351,10 +2338,10 @@ CREATE VIEW macrostrat_api.strat_names_view AS LEFT JOIN macrostrat.strat_names_meta sm ON ((sm.concept_id = s.concept_id))); -ALTER TABLE macrostrat_api.strat_names_view OWNER TO postgres; +ALTER TABLE macrostrat_api.strat_names OWNER TO postgres; -- --- Name: strat_tree; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: strat_tree; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.strat_tree AS @@ -2365,10 +2352,10 @@ CREATE VIEW macrostrat_api.strat_tree AS FROM macrostrat.strat_tree; -ALTER TABLE macrostrat_api.strat_tree OWNER TO postgres; +ALTER TABLE macrostrat_api.strat_tree OWNER TO api_views_owner; -- --- Name: timescales; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: timescales; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.timescales AS @@ -2378,7 +2365,7 @@ CREATE VIEW macrostrat_api.timescales AS FROM macrostrat.timescales; -ALTER TABLE macrostrat_api.timescales OWNER TO postgres; +ALTER TABLE macrostrat_api.timescales OWNER TO api_views_owner; -- -- Name: unit_environs; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -2396,7 +2383,7 @@ CREATE VIEW macrostrat_api.unit_environs AS ALTER TABLE macrostrat_api.unit_environs OWNER TO postgres; -- --- Name: unit_liths; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: unit_liths; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.unit_liths AS @@ -2413,10 +2400,10 @@ CREATE VIEW macrostrat_api.unit_liths AS FROM macrostrat.unit_liths; -ALTER TABLE macrostrat_api.unit_liths OWNER TO postgres; +ALTER TABLE macrostrat_api.unit_liths OWNER TO api_views_owner; -- --- Name: units; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- Name: units; Type: VIEW; Schema: macrostrat_api; Owner: api_views_owner -- CREATE VIEW macrostrat_api.units AS @@ -2437,7 +2424,7 @@ CREATE VIEW macrostrat_api.units AS FROM macrostrat.units; -ALTER TABLE macrostrat_api.units OWNER TO postgres; +ALTER TABLE macrostrat_api.units OWNER TO api_views_owner; -- -- Name: units_view; Type: VIEW; Schema: macrostrat_api; Owner: postgres @@ -3641,6 +3628,13 @@ CREATE OR REPLACE VIEW macrostrat_api.col_group_view AS GROUP BY cg.id, c.project_id; +-- +-- Name: projects project_instead_insert; Type: TRIGGER; Schema: macrostrat_api; Owner: api_views_owner +-- + +CREATE TRIGGER project_instead_insert INSTEAD OF INSERT ON macrostrat_api.projects FOR EACH ROW EXECUTE FUNCTION macrostrat_api.project_insert(); + + -- -- Name: col_areas col_areas_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3649,6 +3643,14 @@ ALTER TABLE ONLY macrostrat.col_areas ADD CONSTRAINT col_areas_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; +-- +-- Name: col_areas col_areas_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_areas + ADD CONSTRAINT col_areas_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + -- -- Name: col_groups col_groups_project_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3665,6 +3667,14 @@ ALTER TABLE ONLY macrostrat.col_refs ADD CONSTRAINT col_refs_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; +-- +-- Name: col_refs col_refs_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + -- -- Name: col_refs col_refs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3673,6 +3683,14 @@ ALTER TABLE ONLY macrostrat.col_refs ADD CONSTRAINT col_refs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; +-- +-- Name: col_refs col_refs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + -- -- Name: cols cols_col_group_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3681,6 +3699,14 @@ ALTER TABLE ONLY macrostrat.cols ADD CONSTRAINT cols_col_group_id_fkey FOREIGN KEY (col_group_id) REFERENCES macrostrat.col_groups(id) ON DELETE CASCADE; +-- +-- Name: cols cols_col_group_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_col_group_id_fkey1 FOREIGN KEY (col_group_id) REFERENCES macrostrat.col_groups(id) ON DELETE CASCADE; + + -- -- Name: cols cols_project_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3689,6 +3715,14 @@ ALTER TABLE ONLY macrostrat.cols ADD CONSTRAINT cols_project_id_fkey FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE; +-- +-- Name: cols cols_project_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE; + + -- -- Name: concepts_places concepts_places_place_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3697,6 +3731,14 @@ ALTER TABLE ONLY macrostrat.concepts_places ADD CONSTRAINT concepts_places_place_id_fkey FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; +-- +-- Name: concepts_places concepts_places_place_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.concepts_places + ADD CONSTRAINT concepts_places_place_id_fkey1 FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + -- -- Name: projects projects_timescale_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3705,6 +3747,14 @@ ALTER TABLE ONLY macrostrat.projects ADD CONSTRAINT projects_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; +-- +-- Name: projects projects_timescale_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.projects + ADD CONSTRAINT projects_timescale_id_fkey1 FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + -- -- Name: sections sections_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3713,6 +3763,14 @@ ALTER TABLE ONLY macrostrat.sections ADD CONSTRAINT sections_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; +-- +-- Name: sections sections_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + -- -- Name: strat_names_places strat_names_places_place_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3721,6 +3779,14 @@ ALTER TABLE ONLY macrostrat.strat_names_places ADD CONSTRAINT strat_names_places_place_id_fkey FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; +-- +-- Name: strat_names_places strat_names_places_place_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_place_id_fkey1 FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + -- -- Name: strat_names_places strat_names_places_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3729,6 +3795,14 @@ ALTER TABLE ONLY macrostrat.strat_names_places ADD CONSTRAINT strat_names_places_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: strat_names_places strat_names_places_strat_name_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_strat_name_id_fkey1 FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + -- -- Name: strat_tree strat_tree_child_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3737,6 +3811,14 @@ ALTER TABLE ONLY macrostrat.strat_tree ADD CONSTRAINT strat_tree_child_fkey FOREIGN KEY (child) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: strat_tree strat_tree_child_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_child_fkey1 FOREIGN KEY (child) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + -- -- Name: strat_tree strat_tree_parent_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3745,6 +3827,14 @@ ALTER TABLE ONLY macrostrat.strat_tree ADD CONSTRAINT strat_tree_parent_fkey FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: strat_tree strat_tree_parent_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_parent_fkey1 FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + -- -- Name: strat_tree strat_tree_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3753,6 +3843,14 @@ ALTER TABLE ONLY macrostrat.strat_tree ADD CONSTRAINT strat_tree_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; +-- +-- Name: strat_tree strat_tree_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + -- -- Name: timescales_intervals timescales_intervals_interval_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3761,6 +3859,14 @@ ALTER TABLE ONLY macrostrat.timescales_intervals ADD CONSTRAINT timescales_intervals_interval_id_fkey FOREIGN KEY (interval_id) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; +-- +-- Name: timescales_intervals timescales_intervals_interval_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_interval_id_fkey1 FOREIGN KEY (interval_id) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + -- -- Name: timescales_intervals timescales_intervals_timescale_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3769,6 +3875,14 @@ ALTER TABLE ONLY macrostrat.timescales_intervals ADD CONSTRAINT timescales_intervals_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; +-- +-- Name: timescales_intervals timescales_intervals_timescale_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_timescale_id_fkey1 FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + -- -- Name: unit_econs unit_econs_econ_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3777,6 +3891,14 @@ ALTER TABLE ONLY macrostrat.unit_econs ADD CONSTRAINT unit_econs_econ_id_fkey FOREIGN KEY (econ_id) REFERENCES macrostrat.econs(id) ON DELETE CASCADE; +-- +-- Name: unit_econs unit_econs_econ_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_econ_id_fkey1 FOREIGN KEY (econ_id) REFERENCES macrostrat.econs(id) ON DELETE CASCADE; + + -- -- Name: unit_econs unit_econs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3785,6 +3907,14 @@ ALTER TABLE ONLY macrostrat.unit_econs ADD CONSTRAINT unit_econs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; +-- +-- Name: unit_econs unit_econs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + -- -- Name: unit_econs unit_econs_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3793,6 +3923,14 @@ ALTER TABLE ONLY macrostrat.unit_econs ADD CONSTRAINT unit_econs_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; +-- +-- Name: unit_econs unit_econs_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + -- -- Name: unit_environs unit_environs_environ_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3801,6 +3939,14 @@ ALTER TABLE ONLY macrostrat.unit_environs ADD CONSTRAINT unit_environs_environ_id_fkey FOREIGN KEY (environ_id) REFERENCES macrostrat.environs(id) ON DELETE CASCADE; +-- +-- Name: unit_environs unit_environs_environ_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_environ_id_fkey1 FOREIGN KEY (environ_id) REFERENCES macrostrat.environs(id) ON DELETE CASCADE; + + -- -- Name: unit_environs unit_environs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3809,6 +3955,14 @@ ALTER TABLE ONLY macrostrat.unit_environs ADD CONSTRAINT unit_environs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; +-- +-- Name: unit_environs unit_environs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + -- -- Name: unit_environs unit_environs_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3817,6 +3971,14 @@ ALTER TABLE ONLY macrostrat.unit_environs ADD CONSTRAINT unit_environs_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; +-- +-- Name: unit_environs unit_environs_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + -- -- Name: unit_lith_atts unit_lith_atts_lith_att_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3825,6 +3987,14 @@ ALTER TABLE ONLY macrostrat.unit_lith_atts ADD CONSTRAINT unit_lith_atts_lith_att_id_fkey FOREIGN KEY (lith_att_id) REFERENCES macrostrat.lith_atts(id) ON DELETE CASCADE; +-- +-- Name: unit_lith_atts unit_lith_atts_lith_att_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_lith_att_id_fkey1 FOREIGN KEY (lith_att_id) REFERENCES macrostrat.lith_atts(id) ON DELETE CASCADE; + + -- -- Name: unit_lith_atts unit_lith_atts_unit_lith_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3833,6 +4003,14 @@ ALTER TABLE ONLY macrostrat.unit_lith_atts ADD CONSTRAINT unit_lith_atts_unit_lith_id_fkey FOREIGN KEY (unit_lith_id) REFERENCES macrostrat.unit_liths(id) ON DELETE CASCADE; +-- +-- Name: unit_lith_atts unit_lith_atts_unit_lith_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_unit_lith_id_fkey1 FOREIGN KEY (unit_lith_id) REFERENCES macrostrat.unit_liths(id) ON DELETE CASCADE; + + -- -- Name: unit_liths unit_liths_lith_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3841,6 +4019,14 @@ ALTER TABLE ONLY macrostrat.unit_liths ADD CONSTRAINT unit_liths_lith_id_fkey FOREIGN KEY (lith_id) REFERENCES macrostrat.liths(id) ON DELETE CASCADE; +-- +-- Name: unit_liths unit_liths_lith_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_lith_id_fkey1 FOREIGN KEY (lith_id) REFERENCES macrostrat.liths(id) ON DELETE CASCADE; + + -- -- Name: unit_liths unit_liths_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3849,6 +4035,14 @@ ALTER TABLE ONLY macrostrat.unit_liths ADD CONSTRAINT unit_liths_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; +-- +-- Name: unit_liths unit_liths_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + -- -- Name: unit_strat_names unit_strat_names_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3857,6 +4051,14 @@ ALTER TABLE ONLY macrostrat.unit_strat_names ADD CONSTRAINT unit_strat_names_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: unit_strat_names unit_strat_names_strat_name_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_strat_name_id_fkey1 FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + -- -- Name: unit_strat_names unit_strat_names_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3865,6 +4067,14 @@ ALTER TABLE ONLY macrostrat.unit_strat_names ADD CONSTRAINT unit_strat_names_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; +-- +-- Name: unit_strat_names unit_strat_names_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + -- -- Name: units units_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3873,6 +4083,14 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; +-- +-- Name: units units_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + -- -- Name: units units_fo_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3881,6 +4099,14 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_fo_fkey FOREIGN KEY (fo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; +-- +-- Name: units units_fo_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_fo_fkey1 FOREIGN KEY (fo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + -- -- Name: units units_lo_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3889,6 +4115,14 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_lo_fkey FOREIGN KEY (lo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; +-- +-- Name: units units_lo_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_lo_fkey1 FOREIGN KEY (lo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + -- -- Name: units units_section_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3897,6 +4131,14 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_section_id_fkey FOREIGN KEY (section_id) REFERENCES macrostrat.sections(id) ON DELETE CASCADE; +-- +-- Name: units units_section_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_section_id_fkey1 FOREIGN KEY (section_id) REFERENCES macrostrat.sections(id) ON DELETE CASCADE; + + -- -- Name: units units_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres -- @@ -3905,6 +4147,671 @@ ALTER TABLE ONLY macrostrat.units ADD CONSTRAINT units_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; +-- +-- Name: SCHEMA macrostrat; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT USAGE ON SCHEMA macrostrat TO api_views_owner; + + +-- +-- Name: SCHEMA macrostrat_api; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT USAGE ON SCHEMA macrostrat_api TO api_views_owner; + + +-- +-- Name: TABLE autocomplete; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.autocomplete TO api_views_owner; + + +-- +-- Name: TABLE col_areas; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_areas TO api_views_owner; + + +-- +-- Name: SEQUENCE col_areas_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_areas_id_seq TO api_views_owner; + + +-- +-- Name: TABLE col_groups; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_groups TO api_views_owner; + + +-- +-- Name: SEQUENCE col_groups_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_groups_id_seq TO api_views_owner; + + +-- +-- Name: TABLE col_refs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_refs TO api_views_owner; + + +-- +-- Name: SEQUENCE col_refs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_refs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE cols; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.cols TO api_views_owner; + + +-- +-- Name: SEQUENCE cols_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.cols_id_seq TO api_views_owner; + + +-- +-- Name: TABLE concepts_places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.concepts_places TO api_views_owner; + + +-- +-- Name: TABLE econs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.econs TO api_views_owner; + + +-- +-- Name: SEQUENCE econs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.econs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE environs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.environs TO api_views_owner; + + +-- +-- Name: SEQUENCE environs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.environs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE grainsize; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.grainsize TO api_views_owner; + + +-- +-- Name: SEQUENCE grainsize_grain_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.grainsize_grain_id_seq TO api_views_owner; + + +-- +-- Name: TABLE intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.intervals TO api_views_owner; + + +-- +-- Name: SEQUENCE intervals_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.intervals_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE intervals_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.intervals_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE lith_atts; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lith_atts TO api_views_owner; + + +-- +-- Name: SEQUENCE lith_atts_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.lith_atts_id_seq TO api_views_owner; + + +-- +-- Name: TABLE liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.liths TO api_views_owner; + + +-- +-- Name: SEQUENCE liths_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.liths_id_seq TO api_views_owner; + + +-- +-- Name: TABLE lookup_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_strat_names TO api_views_owner; + + +-- +-- Name: TABLE lookup_unit_attrs_api; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_attrs_api TO api_views_owner; + + +-- +-- Name: TABLE lookup_unit_intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_intervals TO api_views_owner; + + +-- +-- Name: TABLE lookup_unit_liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_liths TO api_views_owner; + + +-- +-- Name: TABLE lookup_units; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_units TO api_views_owner; + + +-- +-- Name: SEQUENCE lookup_units_unit_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.lookup_units_unit_id_seq TO api_views_owner; + + +-- +-- Name: TABLE measurements; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measurements TO api_views_owner; + + +-- +-- Name: SEQUENCE measurements_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE measurements_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_new_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE measurements_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_new_id_seq1 TO api_views_owner; + + +-- +-- Name: TABLE measuremeta; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measuremeta TO api_views_owner; + + +-- +-- Name: SEQUENCE measuremeta_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measuremeta_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE measuremeta_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measuremeta_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE measures; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measures TO api_views_owner; + + +-- +-- Name: SEQUENCE measures_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measures_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE pbdb_collections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.pbdb_collections TO api_views_owner; + + +-- +-- Name: TABLE pbdb_collections_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.pbdb_collections_strat_names TO api_views_owner; + + +-- +-- Name: TABLE places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.places TO api_views_owner; + + +-- +-- Name: SEQUENCE places_place_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.places_place_id_seq TO api_views_owner; + + +-- +-- Name: TABLE projects; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.projects TO api_views_owner; + + +-- +-- Name: SEQUENCE projects_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.projects_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE projects_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.projects_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE refs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.refs TO api_views_owner; + + +-- +-- Name: SEQUENCE refs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.refs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE sections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.sections TO api_views_owner; + + +-- +-- Name: SEQUENCE sections_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.sections_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE sections_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.sections_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE strat_name_footprints; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_name_footprints TO api_views_owner; + + +-- +-- Name: TABLE strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names TO api_views_owner; + + +-- +-- Name: SEQUENCE strat_names_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_id_seq TO api_views_owner; + + +-- +-- Name: TABLE strat_names_meta; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names_meta TO api_views_owner; + + +-- +-- Name: SEQUENCE strat_names_meta_concept_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_meta_concept_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE strat_names_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE strat_names_places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names_places TO api_views_owner; + + +-- +-- Name: TABLE strat_tree; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_tree TO api_views_owner; + + +-- +-- Name: SEQUENCE strat_tree_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_tree_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE strat_tree_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_tree_new_id_seq1 TO api_views_owner; + + +-- +-- Name: TABLE timescales; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.timescales TO api_views_owner; + + +-- +-- Name: SEQUENCE timescales_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.timescales_id_seq TO api_views_owner; + + +-- +-- Name: TABLE timescales_intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.timescales_intervals TO api_views_owner; + + +-- +-- Name: TABLE unit_econs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_econs TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_econs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_econs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE unit_environs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_environs TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_environs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_environs_id_seq TO api_views_owner; + + +-- +-- Name: TABLE unit_lith_atts; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_lith_atts TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_lith_atts_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_lith_atts_id_seq TO api_views_owner; + + +-- +-- Name: TABLE unit_liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_liths TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_liths_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_liths_id_seq TO api_views_owner; + + +-- +-- Name: TABLE unit_measures; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_measures TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_measures_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_measures_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_measures_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_measures_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE unit_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_strat_names TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_strat_names_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_strat_names_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE unit_strat_names_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_strat_names_new_id_seq TO api_views_owner; + + +-- +-- Name: TABLE units; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.units TO api_views_owner; + + +-- +-- Name: SEQUENCE units_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_id_seq TO api_views_owner; + + +-- +-- Name: TABLE units_sections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.units_sections TO api_views_owner; + + +-- +-- Name: SEQUENCE units_sections_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_sections_id_seq TO api_views_owner; + + +-- +-- Name: SEQUENCE units_sections_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_sections_new_id_seq1 TO api_views_owner; + + +-- +-- Name: TABLE col_form; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.col_form TO api_views_owner; + + +-- +-- Name: TABLE col_group_view; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.col_group_view TO api_views_owner; + + +-- +-- Name: TABLE col_sections; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.col_sections TO api_views_owner; + + +-- +-- Name: TABLE econ_unit; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.econ_unit TO api_views_owner; + + +-- +-- Name: TABLE environ_unit; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.environ_unit TO api_views_owner; + + +-- +-- Name: TABLE lith_attr_unit; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.lith_attr_unit TO api_views_owner; + + +-- +-- Name: TABLE lith_unit; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.lith_unit TO api_views_owner; + + +-- +-- Name: TABLE sections; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.sections TO api_views_owner; + + +-- +-- Name: TABLE strat_names; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.strat_names TO api_views_owner; + + +-- +-- Name: TABLE unit_environs; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.unit_environs TO api_views_owner; + + +-- +-- Name: TABLE units_view; Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat_api.units_view TO api_views_owner; + + -- -- PostgreSQL database dump complete -- diff --git a/v2-transition/services/column-builder/database/fixtures/01-views.sql b/v2-transition/services/column-builder/database/fixtures/01-views.sql index 516919894..823875970 100644 --- a/v2-transition/services/column-builder/database/fixtures/01-views.sql +++ b/v2-transition/services/column-builder/database/fixtures/01-views.sql @@ -2,174 +2,86 @@ CREATE SCHEMA IF NOT EXISTS macrostrat_api; -CREATE OR REPLACE FUNCTION -macrostrat_api.get_projects() RETURNS SETOF macrostrat.projects AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.projects; -END -$$ language plpgsql SECURITY INVOKER; +DROP ROLE IF EXISTS api_views_owner; +CREATE ROLE api_views_owner NOINHERIT; +GRANT USAGE ON SCHEMA macrostrat_api TO api_views_owner; +GRANT USAGE ON SCHEMA macrostrat TO api_views_owner; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO api_views_owner; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO api_views_owner; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.projects AS -SELECT * FROM macrostrat_api.get_projects(); +SELECT * FROM macrostrat.projects; -CREATE OR REPLACE FUNCTION -macrostrat_api.get_cols() RETURNS SETOF macrostrat.cols AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.cols; -END -$$ language plpgsql SECURITY INVOKER; +ALTER VIEW macrostrat_api.projects OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.cols AS -SELECT * FROM macrostrat_api.get_cols(); +SELECT * FROM macrostrat.cols; +ALTER VIEW macrostrat_api.cols OWNER TO api_views_owner; -CREATE OR REPLACE FUNCTION -macrostrat_api.get_col_groups() RETURNS SETOF macrostrat.col_groups AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.col_groups; -END -$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.col_groups AS -SELECT * FROM macrostrat_api.get_col_groups(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_envs() RETURNS SETOF macrostrat.environs AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.environs; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.col_groups; +ALTER VIEW macrostrat_api.col_groups OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.environs AS -SELECT * FROM macrostrat_api.get_envs(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_liths() RETURNS SETOF macrostrat.liths AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.liths; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.environs; +ALTER VIEW macrostrat_api.environs OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.liths AS -SELECT * FROM macrostrat_api.get_liths(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_intervals() RETURNS SETOF macrostrat.intervals AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.intervals; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.liths; +ALTER VIEW macrostrat_api.liths OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.intervals AS -SELECT * FROM macrostrat_api.get_intervals(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_timescales() RETURNS SETOF macrostrat.timescales AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.timescales; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.intervals; +ALTER VIEW macrostrat_api.intervals OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.timescales AS -SELECT * FROM macrostrat_api.get_timescales(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_strat_tree() RETURNS SETOF macrostrat.strat_tree AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.strat_tree; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.timescales; +ALTER VIEW macrostrat_api.timescales OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.strat_tree AS -SELECT * FROM macrostrat_api.get_strat_tree(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_refs() RETURNS SETOF macrostrat.refs AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.refs; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.strat_tree; +ALTER VIEW macrostrat_api.strat_tree OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.refs AS -SELECT * FROM macrostrat_api.get_refs(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_units() RETURNS SETOF macrostrat.units AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.units; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.refs; +ALTER VIEW macrostrat_api.refs OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.units AS -SELECT * FROM macrostrat_api.get_units(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_col_refs() RETURNS SETOF macrostrat.col_refs AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.col_refs; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.units; +ALTER VIEW macrostrat_api.units OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.col_refs AS -SELECT * FROM macrostrat_api.get_col_refs(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_unit_environs() RETURNS SETOF macrostrat.unit_environs AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.unit_environs; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.col_refs; +ALTER VIEW macrostrat_api.col_refs OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.unit_environs AS -SELECT * FROM macrostrat_api.get_unit_environs(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_unit_liths() RETURNS SETOF macrostrat.unit_liths AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.unit_liths; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.unit_environs; +ALTER VIEW macrostrat_api.environs OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.unit_liths AS -SELECT * FROM macrostrat_api.get_unit_liths(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_sections() RETURNS SETOF macrostrat.sections AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.sections; -END -$$ language plpgsql SECURITY INVOKER; +SELECT * FROM macrostrat.unit_liths; +ALTER VIEW macrostrat_api.unit_liths OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.sections AS -SELECT * FROM macrostrat_api.get_sections(); +SELECT * FROM macrostrat.sections; +ALTER VIEW macrostrat_api.sections OWNER TO api_views_owner; -CREATE OR REPLACE FUNCTION -macrostrat_api.get_strat_names() RETURNS SETOF macrostrat.strat_names AS $$ -BEGIN - RETURN QUERY SELECT * FROM macrostrat.strat_names; -END -$$ language plpgsql SECURITY INVOKER; CREATE OR REPLACE VIEW macrostrat_api.strat_names AS -SELECT * FROM macrostrat_api.get_strat_names(); - -CREATE OR REPLACE FUNCTION -macrostrat_api.get_strat_names_view() RETURNS VOID AS $$ -BEGIN - CREATE VIEW macrostrat_api.strat_names_view AS SELECT - s.id, - s.strat_name, - s.rank, - row_to_json(r.*) ref, - row_to_json(sm.*) concept - FROM macrostrat.strat_names s - LEFT JOIN macrostrat.refs r - ON r.id = s.ref_id - LEFT JOIN macrostrat.strat_names_meta sm - ON sm.concept_id = s.concept_id; -END -$$ language plpgsql SECURITY INVOKER; - -SELECT macrostrat_api.get_strat_names_view(); +SELECT +s.id, +s.strat_name, +s.rank, +row_to_json(r.*) ref, +row_to_json(sm.*) concept +FROM macrostrat.strat_names s +LEFT JOIN macrostrat.refs r +ON r.id = s.ref_id +LEFT JOIN macrostrat.strat_names_meta sm +ON sm.concept_id = s.concept_id; +ALTER VIEW macrostrat_api.strat_names OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.col_group_view AS SELECT cg.id, @@ -180,17 +92,20 @@ json_agg(json_build_object('col_id', c.id, 'status_code', c.status_code, 'col_nu FROM macrostrat.col_groups cg LEFT JOIN macrostrat.cols c ON c.col_group_id = cg.id GROUP BY cg.id, c.project_id; +ALTER VIEW macrostrat_api.col_group_view OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.environ_unit AS SELECT e.*, ue.unit_id, ue.ref_id from macrostrat.environs e JOIN macrostrat.unit_environs ue ON e.id = ue.environ_id; +ALTER VIEW macrostrat_api.environ_unit OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.econ_unit AS SELECT e.*, ue.unit_id, ue.ref_id from macrostrat.econs e JOIN macrostrat.unit_econs ue ON e.id = ue.econ_id; +ALTER VIEW macrostrat_api.econ_unit OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.lith_attr_unit AS SELECT @@ -207,6 +122,7 @@ JOIN macrostrat.unit_liths ul ON ul.id = ula.unit_lith_id JOIN macrostrat.liths l ON ul.lith_id = l.id; +ALTER VIEW macrostrat_api.lith_attr_unit OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.lith_unit AS SELECT @@ -224,6 +140,7 @@ ul.unit_id from macrostrat.unit_liths ul JOIN macrostrat.liths l ON ul.lith_id = l.id; +ALTER VIEW macrostrat_api.lith_unit OWNER TO api_views_owner; /*LO is top and FO is bottom*/ CREATE OR REPLACE VIEW macrostrat_api.units_view AS @@ -249,6 +166,7 @@ FROM macrostrat.units u LEFT JOIN macrostrat.intervals fo ON u.fo = fo.id LEFT JOIN macrostrat.intervals lo ON u.lo = lo.id LEFT JOIN macrostrat.strat_names s ON u.strat_name_id = s.id; +ALTER VIEW macrostrat_api.units_view OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.col_sections AS @@ -260,6 +178,7 @@ LEFT JOIN macrostrat.intervals fo ON u.fo = fo.id LEFT JOIN macrostrat.intervals lo ON u.lo = lo.id; +ALTER VIEW macrostrat_api.col_sections OWNER TO api_views_owner; CREATE OR REPLACE VIEW macrostrat_api.col_form AS SELECT @@ -278,4 +197,5 @@ FROM macrostrat.cols c LEFT JOIN macrostrat.col_refs cr ON c.id = cr.col_id LEFT JOIN macrostrat.refs r -ON cr.ref_id = r.id; \ No newline at end of file +ON cr.ref_id = r.id; +ALTER VIEW macrostrat_api.col_form OWNER TO api_views_owner; From 20171b978da1b02bddb400af509afff837982679 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Wed, 30 Mar 2022 19:36:36 +0200 Subject: [PATCH 04/13] some updates --- .../backend/tests/test_z_auth.py | 29 +++- .../urvogel/database/fixtures/auth.sql | 131 ++++++++++-------- .../database/fixtures/test_auth_inserts.sql | 7 +- 3 files changed, 104 insertions(+), 63 deletions(-) diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 37f6ea159..621d2eee9 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -10,7 +10,7 @@ email = "cidzikowski@wisc.edu" password = "gniessrocks" -def login(): +def login(email, password): res = post(base+"/rpc/login", data={"email": email, "pass": password}) token = res.json().get('token') headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} @@ -36,7 +36,7 @@ def test_create_auth(db): res = db.query(sql).fetchall() for row in res: - assert row.get('rolname') in ['api_views_owner','reader', 'writer', 'deleter', 'owner_','anon','authenticator', 'new_user'] + assert row.get('rolname') in ['api_views_owner','anon','authenticator', 'api_user'] def test_pg_extensions(db): sql = """ select extname from pg_extension; """ @@ -78,8 +78,8 @@ def test_login(db): assert len(data) == 0 # make the user an owner - sql = """ insert into auth.user_projects(user_, project, can_upsert, can_delete) - values(1, 1, FALSE, FALSE) """ + sql = """ insert into auth.user_projects(user_, project, privilege) + values(1, 1, 'owner') """ with db.conn.cursor() as cur: cur.execute(sql) @@ -111,7 +111,7 @@ def test_project_create(db): def test_child_data(db): """ add some col-group, col and unit and see that we can access it """ - headers = login() + headers = login(email, password) col_group = {"col_group": "CG1", "col_group_long": "Casey's first fake column group", "project_id":13} res = post(base+"/col_groups", data=col_group, headers=headers) @@ -120,3 +120,22 @@ def test_child_data(db): res = get(base + "/col_groups", headers=headers) assert len(res.json()) == 1 + +def test_rls(db): + """ create a new user with read only access to casey's project, + As owner I should be able to configure user privileges + """ + email = 'app_user@gmail.com' + password = 'appuser1' + params = {"email": email, "pass": password} + + res = post(base+"/rpc/create_user", data=params) + + headers = login('app_user@gmail.com', 'appuser1') + + + res = get(base + "/projects", headers=headers) + data = res.json() + + assert len(data) == 0 + diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index 72f3a4d45..3d70c682f 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -75,14 +75,22 @@ auth.users( role name not null check (length(role) < 512) ); +/* + data privilege descriptions: + - reader: can only SELECT on data + - writer: can SELECT, INSERT, and UPDATE + - deleter: can SELECT, INSERT, UPDATE, and DELETE + - owner: all privileges and can allow other users to access their data + */ +CREATE TYPE auth.data_privileges AS ENUM ('reader', 'writer', 'deleter','owner'); + /* Example of a basic data id to role */ CREATE TABLE IF NOT EXISTS auth.user_projects( id serial primary key, user_ int REFERENCES auth.users(id), project int REFERENCES macrostrat.projects(id), - can_upsert BOOLEAN, -- both insert and update - can_delete BOOLEAN -- can delete + privilege auth.data_privileges ); /* make sure the role being added to user table actually exists!! */ @@ -104,7 +112,6 @@ CREATE trigger ensure_user_role_exists FOR EACH ROW EXECUTE PROCEDURE auth.check_role_exists(); - /* Encrypt the password so it's not just sitting in the table */ CREATE OR REPLACE FUNCTION auth.encrypt_pass() RETURNS trigger AS $$ @@ -174,7 +181,7 @@ DECLARE _role name; BEGIN INSERT INTO auth.users(email, pass, role) - VALUES (email, pass, 'new_user'); + VALUES (email, pass, 'api_user'); SELECT auth.user_role(email, pass) INTO _role; IF _role IS NULL THEN @@ -185,7 +192,6 @@ BEGIN END $$ language plpgsql SECURITY DEFINER; - /*####################### BASE DB ROLES ##########################*/ -- these are the basic auth roles used by postgrest. @@ -198,44 +204,18 @@ GRANT anon TO authenticator; GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; --- read only -DROP ROLE IF EXISTS reader; -CREATE ROLE reader NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO reader; -GRANT SELECT ON ALL TABLES IN SCHEMA macrostrat_api TO reader; - --- can read and insert/update but no delete -DROP ROLE IF EXISTS writer; -CREATE ROLE writer NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO writer; -GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA macrostrat_api TO writer; - --- can delete as well as read and update/insert -DROP ROLE IF EXISTS deleter; -CREATE ROLE deleter NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO deleter; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO deleter; - --- can do everything including create new users, grant priviledges -DROP ROLE IF EXISTS owner_; -CREATE ROLE owner_ NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO owner_; -GRANT USAGE ON SCHEMA auth TO owner_; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO owner_; -GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO owner_; - --- a new user has only the option to create a new project -DROP ROLE IF EXISTS new_user; -CREATE ROLE new_user NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO new_user; -GRANT USAGE ON SCHEMA macrostrat TO new_user; -GRANT USAGE ON SCHEMA auth TO new_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO new_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO new_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO new_user; -GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO new_user; -GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO new_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO new_user; +-- a general api_user, data privileges depend on RLS +DROP ROLE IF EXISTS api_user; +CREATE ROLE api_user NOINHERIT; +GRANT USAGE ON SCHEMA macrostrat_api TO api_user; +GRANT USAGE ON SCHEMA macrostrat TO api_user; +GRANT USAGE ON SCHEMA auth TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO api_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO api_user; /* ################### Row level policies ################### */ @@ -260,12 +240,12 @@ BEGIN IF tg_op = 'INSERT' THEN select macrostrat_api.get_email() into email_; select id from auth.users where users.email = email_ INTO id_; - INSERT INTO auth.user_projects(user_, project, can_upsert, can_delete) - VALUES(id_, new.id, TRUE, TRUE); + INSERT INTO auth.user_projects(user_, project, privilege) + VALUES(id_, new.id, 'owner'); END IF; RETURN new; END -$$ LANGUAGE plpgsql; +$$ LANGUAGE plpgsql SECURITY DEFINER; DROP trigger IF EXISTS user_projects ON macrostrat.projects; CREATE trigger user_projects @@ -281,38 +261,64 @@ BEGIN SELECT macrostrat_api.get_email() INTO email_; RETURN QUERY SELECT up.* FROM auth.user_projects up - JOIN auth.users u - on u.email = email_; + RIGHT JOIN auth.users u + on u.email = email_ + WHERE u.email = email_; END $$ language plpgsql SECURITY DEFINER; +/* users table */ +ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY; + +CREATE POLICY secure_users ON auth.users +USING (email = macrostrat_api.get_email()) +WITH CHECK (email = macrostrat_api.get_email()); + +/* user_projects mapping tables */ +ALTER TABLE auth.user_projects ENABLE ROW LEVEL SECURITY; + +-- Only project owners can view and manipulate project privileges +CREATE POLICY owner_projects ON auth.user_projects +USING (project IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE privilege = 'owner')) +WITH CHECK (project IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE privilege = 'owner')); + /* projects */ ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; CREATE POLICY projects_ ON macrostrat.projects FOR SELECT -USING (id IN (SELECT project FROM macrostrat_api.current_user_projects())); +USING (id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE privilege IN ('reader','writer','deleter','owner'))); +-- anyone can insert a new project CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT WITH CHECK(TRUE); +-- Updates only allowable for writer, deleter or owner CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE -WITH CHECK (TRUE); +WITH CHECK (id IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE privilege IN ('writer','deleter', 'owner') +)); --- id in ( --- SELECT project FROM macrostrat_api.current_user_projects() --- WHERE can_upsert IS TRUE --- ) /* col-groups */ ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT -USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); +USING (project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE privilege IN ('reader','writer','deleter','owner'))); + CREATE POLICY col_group_upsert ON macrostrat.col_groups WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() - WHERE can_upsert IS TRUE)); + WHERE privilege IN ('writer', 'deleter', 'owner'))); /* cols */ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; @@ -320,6 +326,12 @@ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; CREATE POLICY cols_select ON macrostrat.cols FOR SELECT USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); +CREATE POLICY cols_upsert ON macrostrat.cols +WITH CHECK(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE privilege IN ('writer', 'deleter', 'owner') +)); + /* units */ ALTER TABLE macrostrat.units ENABLE ROW LEVEL SECURITY; @@ -328,3 +340,10 @@ USING (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN( SELECT project FROM macrostrat_api.current_user_projects()))); + +CREATE POLICY units_upsert ON macrostrat.units +WITH CHECK (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE privilege IN ('writer', 'deleter', 'owner')))); \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_auth_inserts.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_auth_inserts.sql index 0969d9f8d..e96e1af6c 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_auth_inserts.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/test_auth_inserts.sql @@ -1,2 +1,5 @@ -INSERT INTO auth.users(email, pass, projects,role) VALUES - ('fake_man@fake.com', 'fakepassword', '{1}','owner_'); \ No newline at end of file +INSERT INTO auth.users(email, pass) VALUES + ('fake_man@fake.com', 'fakepassword'); + +INSERT INTO auth.user_projects(user_, project, privilege) VALUES + (1, 1, 'owner'); \ No newline at end of file From d3f34311188ee37ca8f38fe7b532c3c5de27ec26 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Sun, 3 Apr 2022 19:47:37 +0200 Subject: [PATCH 05/13] auth --- .../column-builder/backend/bin/run-tests | 4 +- .../backend/tests/test_z_auth.py | 9 +-- .../urvogel/database/fixtures/auth.sql | 78 ++++++++++--------- .../column-builder/docker-compose.yaml | 2 +- 4 files changed, 50 insertions(+), 43 deletions(-) diff --git a/v2-transition/services/column-builder/backend/bin/run-tests b/v2-transition/services/column-builder/backend/bin/run-tests index d8d144706..8f0369af4 100755 --- a/v2-transition/services/column-builder/backend/bin/run-tests +++ b/v2-transition/services/column-builder/backend/bin/run-tests @@ -8,10 +8,10 @@ result=$( docker ps -q -f name=postgrest ) if [[ -n "$result" ]]; then echo "Rebuilding Postgrest Docker container for testing!" - POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon docker-compose up -d --build postgrest + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon PGUSER=authenticator docker-compose up -d --build postgrest else echo "Starting Docker" - POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon docker-compose up -d + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon PGUSER=authenticator docker-compose up -d fi pytest --pdb diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 621d2eee9..284e496b9 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -46,7 +46,7 @@ def test_pg_extensions(db): assert 'pgjwt' in extensions def test_add_user(db): - + #assert 0 == 1 params = {"email": email, "pass": password} res = post(base+"/rpc/create_user", data=params) @@ -78,14 +78,14 @@ def test_login(db): assert len(data) == 0 # make the user an owner - sql = """ insert into auth.user_projects(user_, project, privilege) - values(1, 1, 'owner') """ + sql = """ insert into auth.user_projects(user_, project, role_id) + values(1, 1, 4) """ with db.conn.cursor() as cur: cur.execute(sql) res = post(base + '/rpc/current_user_projects', headers=headers) - assert len(res.json()) == 1 and res.json()[0].get('id') == 1 + assert len(res.json()) == 1 and res.json()[0].get('project') == 1 res = get(base + "/projects", headers={"Prefer": "return=representation", "Authorization": f'bearer {token}'}) data = res.json() @@ -138,4 +138,3 @@ def test_rls(db): data = res.json() assert len(data) == 0 - diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index 3d70c682f..252534032 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -24,14 +24,6 @@ will be things that the user creates themselves. But they should also be able to General DB roles: -postgres- the ultimate super-user -admin - can view, edit, create, and delete data and users -creator/owner - can view, edit, create and delete their own data and can create new users with permissions for their data - -read-only - can only read specified data -read+write - can select, update and insert -read+write+delete - can select, update, insert and delete - Handle users in-database: auth schema, users table @@ -75,14 +67,18 @@ auth.users( role name not null check (length(role) < 512) ); -/* - data privilege descriptions: - - reader: can only SELECT on data - - writer: can SELECT, INSERT, and UPDATE - - deleter: can SELECT, INSERT, UPDATE, and DELETE - - owner: all privileges and can allow other users to access their data - */ -CREATE TYPE auth.data_privileges AS ENUM ('reader', 'writer', 'deleter','owner'); +-- data privilege roles +CREATE TABLE IF NOT EXISTS auth.data_roles( + id SERIAL PRIMARY KEY, + role text, + description text +); +-- default data roles +INSERT INTO auth.data_roles(role, description) VALUES + ('reader', 'user can only perform SELECT on data'), + ('writer', 'user can SELECT, INSERT, and UPDATE'), + ('deleter', 'user can SELECT, INSERT, and UPDATE'), + ('manager', 'user encompasses privileges of deleter and can manage user permissions on data'); /* Example of a basic data id to role */ CREATE TABLE IF NOT EXISTS @@ -90,7 +86,7 @@ auth.user_projects( id serial primary key, user_ int REFERENCES auth.users(id), project int REFERENCES macrostrat.projects(id), - privilege auth.data_privileges + role_id integer REFERENCES auth.data_roles(id) ); /* make sure the role being added to user table actually exists!! */ @@ -198,11 +194,16 @@ $$ language plpgsql SECURITY DEFINER; DROP ROLE IF EXISTS anon; CREATE ROLE anon NOINHERIT; DROP ROLE IF EXISTS authenticator; -CREATE ROLE authenticator NOINHERIT; +CREATE ROLE authenticator NOINHERIT LOGIN; GRANT anon TO authenticator; +GRANT USAGE ON SCHEMA macrostrat_api TO anon; +GRANT USAGE ON SCHEMA macrostrat_api TO authenticator; + GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO authenticator; -- a general api_user, data privileges depend on RLS DROP ROLE IF EXISTS api_user; @@ -217,6 +218,8 @@ GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_user; GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_user; GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO api_user; +GRANT api_user to authenticator; + /* ################### Row level policies ################### */ @@ -236,12 +239,14 @@ auth.user_project_insert() RETURNS trigger AS $$ DECLARE email_ text; id_ int; + manager_id int; BEGIN IF tg_op = 'INSERT' THEN select macrostrat_api.get_email() into email_; select id from auth.users where users.email = email_ INTO id_; - INSERT INTO auth.user_projects(user_, project, privilege) - VALUES(id_, new.id, 'owner'); + SELECT id FROM auth.data_roles WHERE role = 'manager' INTO manager_id; + INSERT INTO auth.user_projects(user_, project, role_id) + VALUES(id_, new.id, manager_id); END IF; RETURN new; END @@ -254,15 +259,18 @@ CREATE trigger user_projects EXECUTE PROCEDURE auth.user_project_insert(); CREATE OR REPLACE FUNCTION -macrostrat_api.current_user_projects() RETURNS SETOF auth.user_projects AS $$ +macrostrat_api.current_user_projects() +RETURNS TABLE (project integer, role text) AS $$ DECLARE email_ text; BEGIN SELECT macrostrat_api.get_email() INTO email_; RETURN QUERY - SELECT up.* FROM auth.user_projects up - RIGHT JOIN auth.users u - on u.email = email_ + SELECT up.project, adr.role FROM auth.user_projects up + JOIN auth.users u + on u.id = up.user_ + JOIN auth.data_roles adr + ON adr.id = up.role_id WHERE u.email = email_; END $$ language plpgsql SECURITY DEFINER; @@ -277,14 +285,14 @@ WITH CHECK (email = macrostrat_api.get_email()); /* user_projects mapping tables */ ALTER TABLE auth.user_projects ENABLE ROW LEVEL SECURITY; --- Only project owners can view and manipulate project privileges -CREATE POLICY owner_projects ON auth.user_projects +-- Only project managers can view and manipulate project privileges +CREATE POLICY manager_projects ON auth.user_projects USING (project IN ( SELECT project from macrostrat_api.current_user_projects() - WHERE privilege = 'owner')) + WHERE role = 'manager')) WITH CHECK (project IN ( SELECT project from macrostrat_api.current_user_projects() - WHERE privilege = 'owner')); + WHERE role = 'manager')); /* projects */ @@ -293,17 +301,17 @@ ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; CREATE POLICY projects_ ON macrostrat.projects FOR SELECT USING (id IN ( SELECT project FROM macrostrat_api.current_user_projects() - WHERE privilege IN ('reader','writer','deleter','owner'))); + WHERE role IN ('reader','writer','deleter','manager'))); -- anyone can insert a new project CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT WITH CHECK(TRUE); --- Updates only allowable for writer, deleter or owner +-- Updates only allowable for writer, deleter or manager CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE WITH CHECK (id IN ( SELECT project from macrostrat_api.current_user_projects() - WHERE privilege IN ('writer','deleter', 'owner') + WHERE role IN ('writer','deleter', 'manager') )); /* col-groups */ @@ -312,13 +320,13 @@ ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT USING (project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() - WHERE privilege IN ('reader','writer','deleter','owner'))); + WHERE role IN ('reader','writer','deleter','manager'))); CREATE POLICY col_group_upsert ON macrostrat.col_groups WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() - WHERE privilege IN ('writer', 'deleter', 'owner'))); + WHERE role IN ('writer', 'deleter', 'manager'))); /* cols */ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; @@ -329,7 +337,7 @@ USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects() CREATE POLICY cols_upsert ON macrostrat.cols WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() - WHERE privilege IN ('writer', 'deleter', 'owner') + WHERE role IN ('writer', 'deleter', 'manager') )); /* units */ @@ -346,4 +354,4 @@ WITH CHECK (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN( SELECT project FROM macrostrat_api.current_user_projects() - WHERE privilege IN ('writer', 'deleter', 'owner')))); \ No newline at end of file + WHERE role IN ('writer', 'deleter', 'manager')))); \ No newline at end of file diff --git a/v2-transition/services/column-builder/docker-compose.yaml b/v2-transition/services/column-builder/docker-compose.yaml index 8771b495c..87d13580e 100644 --- a/v2-transition/services/column-builder/docker-compose.yaml +++ b/v2-transition/services/column-builder/docker-compose.yaml @@ -16,7 +16,7 @@ services: PGRST_DB_URI: postgres://${PGUSER}:@db:5432/${POSTGRES_DB} PGRST_DB_SCHEMA: macrostrat_api PGRST_JWT_SECRET: ${PGRST_JWT_SECRET} - PGRST_DB_ANON_ROLE: ${PGUSER} #In production this role should not be the same as the one used for the connection + PGRST_DB_ANON_ROLE: ${PGRST_DB_ANON_ROLE} PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3001 depends_on: - db From d0102fff7be9ec977e9d9ad527b25f4c1ead907c Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Tue, 5 Apr 2022 13:29:11 +0200 Subject: [PATCH 06/13] auth changes --- .../backend/tests/test_z_auth.py | 29 +++++++++-- .../urvogel/database/fixtures/auth.sql | 49 ++++++++++++------- 2 files changed, 58 insertions(+), 20 deletions(-) diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 284e496b9..907d415c8 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -1,7 +1,5 @@ -from email import header from requests import get, post, patch, put from urvogel.database.fixtures import get_sql -from psycopg.sql import SQL, Literal base= "http://127.0.0.1:3001" @@ -122,7 +120,8 @@ def test_child_data(db): assert len(res.json()) == 1 def test_rls(db): - """ create a new user with read only access to casey's project, + """ + create a new user with read only access to casey's project, As owner I should be able to configure user privileges """ email = 'app_user@gmail.com' @@ -138,3 +137,27 @@ def test_rls(db): data = res.json() assert len(data) == 0 + +def test_user_management(): + """ """ + headers = login(email,password) + + res = get(base + "/user_projects", headers=headers) + + assert len(res.json()) == 2 + + headers_ = login('app_user@gmail.com', 'appuser1') + res = get(base + "/user_projects", headers=headers_) + assert len(res.json()) == 0 + + # make app_user a reader for project 13 + data = {"user_":2, "project":13, "role_id": 1 } + res = post(base + "/user_projects", data=data, headers=headers) + + assert res.status_code == 201 + + res = get(base + "/projects", headers=headers_) + data = res.json() + assert len(data) == 1 + assert data[0].get('id') == 13 + assert 0 ==1 \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql index 252534032..0f735b688 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql @@ -163,8 +163,8 @@ BEGIN row_to_json(r), 'reallyreallyreallyreallyverysafesafesafesafe' ) AS token FROM ( - SELECT _role as role, login.email as email, - extract(epoch FROM now())::integer + 60*60 AS exp + SELECT 'api_views_owner' as role, login.email as email, + extract(epoch FROM now())::integer + 86400 AS exp --expires in 1 day ) r INTO result; RETURN result; @@ -177,7 +177,7 @@ DECLARE _role name; BEGIN INSERT INTO auth.users(email, pass, role) - VALUES (email, pass, 'api_user'); + VALUES (email, pass, 'api_views_owner'); SELECT auth.user_role(email, pass) INTO _role; IF _role IS NULL THEN @@ -206,19 +206,11 @@ GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator; GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO authenticator; -- a general api_user, data privileges depend on RLS -DROP ROLE IF EXISTS api_user; -CREATE ROLE api_user NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO api_user; -GRANT USAGE ON SCHEMA macrostrat TO api_user; -GRANT USAGE ON SCHEMA auth TO api_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO api_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO api_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO api_user; -GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_user; -GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON auth.users TO api_user; - -GRANT api_user to authenticator; +GRANT USAGE ON SCHEMA auth TO api_views_owner; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO api_views_owner; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_views_owner; + +GRANT api_views_owner to authenticator; /* ################### Row level policies ################### */ @@ -354,4 +346,27 @@ WITH CHECK (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN( SELECT project FROM macrostrat_api.current_user_projects() - WHERE role IN ('writer', 'deleter', 'manager')))); \ No newline at end of file + WHERE role IN ('writer', 'deleter', 'manager')))); + +CREATE OR REPLACE VIEW macrostrat_api.users AS +SELECT * FROM auth.users; +ALTER VIEW macrostrat_api.users OWNER TO api_views_owner; + +CREATE OR REPLACE VIEW macrostrat_api.user_projects AS +SELECT * FROM auth.user_projects; +ALTER VIEW macrostrat_api.user_projects OWNER TO api_views_owner; + +CREATE OR REPLACE VIEW macrostrat_api.data_roles AS +SELECT * FROM auth.data_roles; +ALTER VIEW macrostrat_api.data_roles OWNER TO api_views_owner; + +ALTER TABLE auth.data_roles ENABLE ROW LEVEL SECURITY; + +CREATE POLICY data_roles_select ON auth.data_roles FOR SELECT +USING(TRUE); + +CREATE POLICY data_roles_update ON auth.data_roles FOR UPDATE +USING (role NOT IN('reader','writer','deleter', 'manager')); + +CREATE POLICY data_roles_insert ON auth.data_roles FOR INSERT +WITH CHECK(role NOT IN ('reader', 'writer', 'deleter', 'manager')); \ No newline at end of file From ee22fad8c2a8148452bc3bb20d8bd4b647224f37 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Tue, 5 Apr 2022 21:38:51 +0200 Subject: [PATCH 07/13] beginning auth frontend --- .../database/db-alterations/00-projects.sql | 20 + .../database/fixtures/01-views.sql | 60 +-- .../database/fixtures/02-auth.sql | 349 ++++++++++++++++++ .../column-builder/docker-compose.yaml | 4 +- 4 files changed, 401 insertions(+), 32 deletions(-) create mode 100644 v2-transition/services/column-builder/database/db-alterations/00-projects.sql create mode 100644 v2-transition/services/column-builder/database/fixtures/02-auth.sql diff --git a/v2-transition/services/column-builder/database/db-alterations/00-projects.sql b/v2-transition/services/column-builder/database/db-alterations/00-projects.sql new file mode 100644 index 000000000..d3d026de3 --- /dev/null +++ b/v2-transition/services/column-builder/database/db-alterations/00-projects.sql @@ -0,0 +1,20 @@ +CREATE TABLE IF NOT EXISTS macrostrat.projects( + id SERIAL PRIMARY KEY, + project text, + descrip text, + timescale_id integer REFERENCES macrostrat.timescales(id) +); + +INSERT INTO "macrostrat"."projects"("id","project","descrip","timescale_id") +VALUES +(1,E'North America',E'Composite column dataset for the USA and Canada.',1), +(3,E'eODP',E'Comprehensive dataset capturing all offshore drilling sites and holes. Holes at each site are captured as \'section\' column types and meters below sea floor (mbsf) are encoded by \'t_pos\' and \'b_pos\' when \'show_position\' parameter is included. Project led by Andy Fraass, Leah LeVay, Jocelyn Sessa, and Shanan Peters.',1), +(4,E'Deep Sea',E'Offshore drilling sites completely cored from sea floor into or near basement rocks. Most sites in this compilation are composited manually from multiple holes into a single representation for the site. Data compiled from offshore drilling reports by S.E. Peters, D.C. Kelly, and A.Fraass. See project_id=3 (\'eODP\') for complete offshore drilling data and associated measurements.',5), +(5,E'New Zealand',E'Primarily measured section-type columns for Late Cretaceous to Recent.',6), +(6,E'Australia',E'Placeholder for anticipated column entry work.',1), +(7,E'Caribbean',E'Composite column dataset for the Caribbean region, including the eastern Gulf Coast of Mexico and Central America.',1), +(8,E'South America',E'Composite column dataset for South America.',1), +(9,E'Africa',E'Composite column dataset for Africa.',1), +(10,E'North American Ediacaran',E'Composite columns of intermediate scale resolution that are comprehensive for the Ediacaran System of present-day North America and adjacent continental blocks formerly part of North America. Compiled by D. Segessenman as part of his Ph.D.',1), +(11,E'North American Cretaceous',E'Cretaceous-focused intermediate scale resolution section data set compiled by Shan Ye as part of his Ph.D.',1), +(12,E'Indonesia',E'Composite column dataset for Indonesia. Compiled principally by Afiqah Ahmad Rafi as part of her senior thesis at UW-Madison.',1); \ No newline at end of file diff --git a/v2-transition/services/column-builder/database/fixtures/01-views.sql b/v2-transition/services/column-builder/database/fixtures/01-views.sql index 823875970..328ffba62 100644 --- a/v2-transition/services/column-builder/database/fixtures/01-views.sql +++ b/v2-transition/services/column-builder/database/fixtures/01-views.sql @@ -2,71 +2,71 @@ CREATE SCHEMA IF NOT EXISTS macrostrat_api; -DROP ROLE IF EXISTS api_views_owner; -CREATE ROLE api_views_owner NOINHERIT; -GRANT USAGE ON SCHEMA macrostrat_api TO api_views_owner; -GRANT USAGE ON SCHEMA macrostrat TO api_views_owner; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO api_views_owner; -GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO api_views_owner; -GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_views_owner; +DROP ROLE IF EXISTS api_user; +CREATE ROLE api_user NOINHERIT; +GRANT USAGE ON SCHEMA macrostrat_api TO api_user; +GRANT USAGE ON SCHEMA macrostrat TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat_api TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA macrostrat TO api_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA macrostrat TO api_user; CREATE OR REPLACE VIEW macrostrat_api.projects AS SELECT * FROM macrostrat.projects; -ALTER VIEW macrostrat_api.projects OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.projects OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.cols AS SELECT * FROM macrostrat.cols; -ALTER VIEW macrostrat_api.cols OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.cols OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.col_groups AS SELECT * FROM macrostrat.col_groups; -ALTER VIEW macrostrat_api.col_groups OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.col_groups OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.environs AS SELECT * FROM macrostrat.environs; -ALTER VIEW macrostrat_api.environs OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.environs OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.liths AS SELECT * FROM macrostrat.liths; -ALTER VIEW macrostrat_api.liths OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.liths OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.intervals AS SELECT * FROM macrostrat.intervals; -ALTER VIEW macrostrat_api.intervals OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.intervals OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.timescales AS SELECT * FROM macrostrat.timescales; -ALTER VIEW macrostrat_api.timescales OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.timescales OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.strat_tree AS SELECT * FROM macrostrat.strat_tree; -ALTER VIEW macrostrat_api.strat_tree OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.strat_tree OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.refs AS SELECT * FROM macrostrat.refs; -ALTER VIEW macrostrat_api.refs OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.refs OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.units AS SELECT * FROM macrostrat.units; -ALTER VIEW macrostrat_api.units OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.units OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.col_refs AS SELECT * FROM macrostrat.col_refs; -ALTER VIEW macrostrat_api.col_refs OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.col_refs OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.unit_environs AS SELECT * FROM macrostrat.unit_environs; -ALTER VIEW macrostrat_api.environs OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.environs OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.unit_liths AS SELECT * FROM macrostrat.unit_liths; -ALTER VIEW macrostrat_api.unit_liths OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.unit_liths OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.sections AS SELECT * FROM macrostrat.sections; -ALTER VIEW macrostrat_api.sections OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.sections OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.strat_names AS @@ -81,7 +81,7 @@ LEFT JOIN macrostrat.refs r ON r.id = s.ref_id LEFT JOIN macrostrat.strat_names_meta sm ON sm.concept_id = s.concept_id; -ALTER VIEW macrostrat_api.strat_names OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.strat_names OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.col_group_view AS SELECT cg.id, @@ -92,20 +92,20 @@ json_agg(json_build_object('col_id', c.id, 'status_code', c.status_code, 'col_nu FROM macrostrat.col_groups cg LEFT JOIN macrostrat.cols c ON c.col_group_id = cg.id GROUP BY cg.id, c.project_id; -ALTER VIEW macrostrat_api.col_group_view OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.col_group_view OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.environ_unit AS SELECT e.*, ue.unit_id, ue.ref_id from macrostrat.environs e JOIN macrostrat.unit_environs ue ON e.id = ue.environ_id; -ALTER VIEW macrostrat_api.environ_unit OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.environ_unit OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.econ_unit AS SELECT e.*, ue.unit_id, ue.ref_id from macrostrat.econs e JOIN macrostrat.unit_econs ue ON e.id = ue.econ_id; -ALTER VIEW macrostrat_api.econ_unit OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.econ_unit OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.lith_attr_unit AS SELECT @@ -122,7 +122,7 @@ JOIN macrostrat.unit_liths ul ON ul.id = ula.unit_lith_id JOIN macrostrat.liths l ON ul.lith_id = l.id; -ALTER VIEW macrostrat_api.lith_attr_unit OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.lith_attr_unit OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.lith_unit AS SELECT @@ -140,7 +140,7 @@ ul.unit_id from macrostrat.unit_liths ul JOIN macrostrat.liths l ON ul.lith_id = l.id; -ALTER VIEW macrostrat_api.lith_unit OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.lith_unit OWNER TO api_user; /*LO is top and FO is bottom*/ CREATE OR REPLACE VIEW macrostrat_api.units_view AS @@ -166,7 +166,7 @@ FROM macrostrat.units u LEFT JOIN macrostrat.intervals fo ON u.fo = fo.id LEFT JOIN macrostrat.intervals lo ON u.lo = lo.id LEFT JOIN macrostrat.strat_names s ON u.strat_name_id = s.id; -ALTER VIEW macrostrat_api.units_view OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.units_view OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.col_sections AS @@ -178,7 +178,7 @@ LEFT JOIN macrostrat.intervals fo ON u.fo = fo.id LEFT JOIN macrostrat.intervals lo ON u.lo = lo.id; -ALTER VIEW macrostrat_api.col_sections OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.col_sections OWNER TO api_user; CREATE OR REPLACE VIEW macrostrat_api.col_form AS SELECT @@ -198,4 +198,4 @@ LEFT JOIN macrostrat.col_refs cr ON c.id = cr.col_id LEFT JOIN macrostrat.refs r ON cr.ref_id = r.id; -ALTER VIEW macrostrat_api.col_form OWNER TO api_views_owner; +ALTER VIEW macrostrat_api.col_form OWNER TO api_user; diff --git a/v2-transition/services/column-builder/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/database/fixtures/02-auth.sql new file mode 100644 index 000000000..3097b9dfc --- /dev/null +++ b/v2-transition/services/column-builder/database/fixtures/02-auth.sql @@ -0,0 +1,349 @@ +/* Authentication in db using postgrest https://postgrest.org/en/stable/auth.html +Postgrest uses JWT to authenticate incoming requests, but the db can authorize db queries based +on users. + + +authenticator is passed via db-uri +anon: db-anon-role (PGRST_DB_ANON_ROLE) +jwt-secret (PGRST_JWT_SECRET) + + +HOW LOGIN WORKS --> { + take username and password, + get the role and any other info we want tokenized, + if login successful --> return json token +} + +Generate JWT in SQL ---> pgjwt +https://github.com/michelp/pgjwt +https://app.bountysource.com/issues/89971002-example-code-to-show-how-to-install-pgjwt-extension-in-docker + + +How to access info on JWT for the current user --> to be user in policy creation:: +current_setting('request.jwt.claims', true)::json->>'username'; + + +*/ + + +/* AUTH schema and functions */ +DROP SCHEMA auth CASCADE; +CREATE SCHEMA auth; + + +/* necesary extenstions */ +CREATE EXTENSION IF NOT EXISTS pgcrypto; +CREATE EXTENSION IF NOT EXISTS pgjwt; + +/* an auth user table */ +CREATE TABLE IF NOT EXISTS +auth.users( + id serial primary key, + username text not null, + pass text not null check (length(pass) < 512), + role name not null check (length(role) < 512) +); + +-- data privilege roles +CREATE TABLE IF NOT EXISTS auth.data_roles( + id SERIAL PRIMARY KEY, + role text, + description text +); +-- default data roles +INSERT INTO auth.data_roles(role, description) VALUES + ('reader', 'user can only perform SELECT on data'), + ('writer', 'user can SELECT, INSERT, and UPDATE'), + ('deleter', 'user can SELECT, INSERT, and UPDATE'), + ('manager', 'user encompasses privileges of deleter and can manage user permissions on data'); + +/* Example of a basic data id to role */ +CREATE TABLE IF NOT EXISTS +auth.user_projects( + id serial primary key, + user_ int REFERENCES auth.users(id), + project int REFERENCES macrostrat.projects(id), + role_id integer REFERENCES auth.data_roles(id) +); + +/* make sure the role being added to user table actually exists!! */ +CREATE OR REPLACE FUNCTION +auth.check_role_exists() RETURNS trigger AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles AS r WHERE r.rolname = new.role) THEN + raise foreign_key_violation USING message = + 'unknown database role: ' || new.role; + RETURN NULL; + END IF; + RETURN new; +END +$$ LANGUAGE plpgsql; + +DROP trigger IF EXISTS ensure_user_role_exists ON auth.users; +CREATE trigger ensure_user_role_exists + BEFORE INSERT OR UPDATE ON auth.users + FOR EACH ROW + EXECUTE PROCEDURE auth.check_role_exists(); + +/* Encrypt the password so it's not just sitting in the table */ +CREATE OR REPLACE FUNCTION +auth.encrypt_pass() RETURNS trigger AS $$ +BEGIN + IF tg_op = 'INSERT' OR new.pass <> old.pass THEN + new.pass := public.crypt(new.pass, public.gen_salt('md5')); + END IF; + RETURN new; +END +$$ LANGUAGE plpgsql; + +DROP trigger IF EXISTS encrypt_pass ON auth.users; +CREATE trigger encrypt_pass + BEFORE INSERT OR UPDATE ON auth.users + FOR EACH ROW + EXECUTE PROCEDURE auth.encrypt_pass(); + + +/* Access the stored role on a user -- used in login! +*/ +CREATE OR REPLACE FUNCTION +auth.user_role(username TEXT, pass TEXT) RETURNS name + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN ( + SELECT role FROM auth.users + WHERE users.username = user_role.username + AND users.pass = public.crypt(user_role.pass, users.pass) + ); +END; +$$; + +CREATE TYPE auth.jwt_token AS ( + token text +); + +/* +Login function! + */ +CREATE OR REPLACE FUNCTION +macrostrat_api.login(username text, pass text) RETURNS auth.jwt_token AS $$ +DECLARE + _role name; + result auth.jwt_token; +BEGIN + SELECT auth.user_role(username, pass) INTO _role; + IF _role IS NULL THEN + raise invalid_password using message = 'invalid user or password'; + END IF; + -- sign function comes from pgjwt extension. + SELECT sign( + row_to_json(r), 'reallyreallyreallyreallyverysafesafesafesafe' + ) AS token + FROM ( + SELECT 'api_user' as role, login.username as username, + extract(epoch FROM now())::integer + 86400 AS exp --expires in 1 day + ) r + INTO result; + RETURN result; +END +$$ language plpgsql SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION +macrostrat_api.create_user(username text, pass text) RETURNS BOOLEAN AS $$ +DECLARE + _role name; +BEGIN + INSERT INTO auth.users(username, pass, role) + VALUES (username, pass, 'api_user'); + SELECT auth.user_role(username, pass) INTO _role; + + IF _role IS NULL THEN + RETURN FALSE; + END IF; + + RETURN TRUE; +END +$$ language plpgsql SECURITY DEFINER; + +/*####################### BASE DB ROLES ##########################*/ + +-- these are the basic auth roles used by postgrest. +DROP ROLE IF EXISTS anon; +CREATE ROLE anon NOINHERIT; +DROP ROLE IF EXISTS authenticator; +CREATE ROLE authenticator NOINHERIT LOGIN; +GRANT anon TO authenticator; + +GRANT USAGE ON SCHEMA macrostrat_api TO anon; +GRANT USAGE ON SCHEMA macrostrat_api TO authenticator; + +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO authenticator; + +-- a general api_user, data privileges depend on RLS +GRANT USAGE ON SCHEMA auth TO api_user; +GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO api_user; +GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_user; + +GRANT api_user to authenticator; + +/* ################### Row level policies ################### */ + + +/* function to get username off of jwt claims*/ +CREATE OR REPLACE FUNCTION +macrostrat_api.get_username() returns text AS $$ +DECLARE + username_ text; +BEGIN + SELECT current_setting('request.jwt.claims', true)::json->>'username' INTO username_; +RETURN username_; +END +$$language plpgsql SECURITY DEFINER; + +CREATE OR REPLACE FUNCTION +auth.user_project_insert() RETURNS trigger AS $$ +DECLARE + username_ text; + id_ int; + manager_id int; +BEGIN + IF tg_op = 'INSERT' THEN + select macrostrat_api.get_username() into username_; + select id from auth.users where users.username = username_ INTO id_; + SELECT id FROM auth.data_roles WHERE role = 'manager' INTO manager_id; + INSERT INTO auth.user_projects(user_, project, role_id) + VALUES(id_, new.id, manager_id); + END IF; + RETURN new; +END +$$ LANGUAGE plpgsql SECURITY DEFINER; + +DROP trigger IF EXISTS user_projects ON macrostrat.projects; +CREATE trigger user_projects + AFTER INSERT ON macrostrat.projects + FOR EACH ROW + EXECUTE PROCEDURE auth.user_project_insert(); + +CREATE OR REPLACE FUNCTION +macrostrat_api.current_user_projects() +RETURNS TABLE (project integer, role text) AS $$ +DECLARE + username_ text; +BEGIN + SELECT macrostrat_api.get_username() INTO username_; + RETURN QUERY + SELECT up.project, adr.role FROM auth.user_projects up + JOIN auth.users u + on u.id = up.user_ + JOIN auth.data_roles adr + ON adr.id = up.role_id + WHERE u.username = username_; +END +$$ language plpgsql SECURITY DEFINER; + +/* users table */ +ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY; + +CREATE POLICY secure_users ON auth.users +USING (username = macrostrat_api.get_username()) +WITH CHECK (username = macrostrat_api.get_username()); + +/* user_projects mapping tables */ +ALTER TABLE auth.user_projects ENABLE ROW LEVEL SECURITY; + +-- Only project managers can view and manipulate project privileges +CREATE POLICY manager_projects ON auth.user_projects +USING (project IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE role = 'manager')) +WITH CHECK (project IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE role = 'manager')); + + +/* projects */ +ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; + +CREATE POLICY projects_ ON macrostrat.projects FOR SELECT +USING (id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('reader','writer','deleter','manager'))); + +-- anyone can insert a new project +CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT +WITH CHECK(TRUE); + +-- Updates only allowable for writer, deleter or manager +CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE +WITH CHECK (id IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE role IN ('writer','deleter', 'manager') +)); + +/* col-groups */ +ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; + +CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT +USING (project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('reader','writer','deleter','manager'))); + + +CREATE POLICY col_group_upsert ON macrostrat.col_groups +WITH CHECK(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager'))); + +/* cols */ +ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; + +CREATE POLICY cols_select ON macrostrat.cols FOR SELECT +USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); + +CREATE POLICY cols_upsert ON macrostrat.cols +WITH CHECK(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager') +)); + +/* units */ +ALTER TABLE macrostrat.units ENABLE ROW LEVEL SECURITY; + +CREATE POLICY units_select ON macrostrat.units FOR SELECT +USING (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT project FROM macrostrat_api.current_user_projects()))); + +CREATE POLICY units_upsert ON macrostrat.units +WITH CHECK (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager')))); + +CREATE OR REPLACE VIEW macrostrat_api.users AS +SELECT * FROM auth.users; +ALTER VIEW macrostrat_api.users OWNER TO api_user; + +CREATE OR REPLACE VIEW macrostrat_api.user_projects AS +SELECT * FROM auth.user_projects; +ALTER VIEW macrostrat_api.user_projects OWNER TO api_user; + +CREATE OR REPLACE VIEW macrostrat_api.data_roles AS +SELECT * FROM auth.data_roles; +ALTER VIEW macrostrat_api.data_roles OWNER TO api_user; + +ALTER TABLE auth.data_roles ENABLE ROW LEVEL SECURITY; + +CREATE POLICY data_roles_select ON auth.data_roles FOR SELECT +USING(TRUE); + +CREATE POLICY data_roles_update ON auth.data_roles FOR UPDATE +USING (role NOT IN('reader','writer','deleter', 'manager')); + +CREATE POLICY data_roles_insert ON auth.data_roles FOR INSERT +WITH CHECK(role NOT IN ('reader', 'writer', 'deleter', 'manager')); \ No newline at end of file diff --git a/v2-transition/services/column-builder/docker-compose.yaml b/v2-transition/services/column-builder/docker-compose.yaml index 87d13580e..5a0156f27 100644 --- a/v2-transition/services/column-builder/docker-compose.yaml +++ b/v2-transition/services/column-builder/docker-compose.yaml @@ -13,10 +13,10 @@ services: ports: - "3001:3000" environment: - PGRST_DB_URI: postgres://${PGUSER}:@db:5432/${POSTGRES_DB} + PGRST_DB_URI: postgres://authenticator:@db:5432/column_data_auth PGRST_DB_SCHEMA: macrostrat_api PGRST_JWT_SECRET: ${PGRST_JWT_SECRET} - PGRST_DB_ANON_ROLE: ${PGRST_DB_ANON_ROLE} + PGRST_DB_ANON_ROLE: anon PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3001 depends_on: - db From 5c5d65601b19cc0d4389f781bb6f15f1dccf4cb0 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Thu, 7 Apr 2022 16:17:39 +0200 Subject: [PATCH 08/13] update --- .../column-builder/database/bin/dump-burwell | 33 ++++++------------- .../database/fixtures/02-auth.sql | 13 +++++--- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/v2-transition/services/column-builder/database/bin/dump-burwell b/v2-transition/services/column-builder/database/bin/dump-burwell index 08a32578f..ade945add 100755 --- a/v2-transition/services/column-builder/database/bin/dump-burwell +++ b/v2-transition/services/column-builder/database/bin/dump-burwell @@ -35,7 +35,7 @@ check() } ############################ variables ################################ -dbname=burwell +dbname=column_data local_db=column_data container_name=db db_user=postgres @@ -68,25 +68,12 @@ pg_dump -Fc -p $local_forward -h localhost -U postgres \ $dbname \ | docker-compose exec -T $container_name pg_restore -v -U$db_user -d $local_db -echo -echo "Do you wish to make alterations?" -echo "Alterations to be made: " -echo " - Add the projects table (data copy and based from MariaDB)" -echo " - Remove unused columns (ex. lo_h, fo_h from cols)" -echo " - Reset Primary Key Sequences" -echo -n "Do you wish to continue?(Y/n): " -read FK -if [[ "$FK" = "Y" || "$FK" = "y" ]] - then - for file in `dirname $0`/../db-alterations/*.sql - do - `dirname $0`/./run-sql-file -f $file -c $container_name -d $local_db -U $db_user - done - for f in `dirname $0`/../fixtures/*.sql - do - `dirname $0`/./run-sql-file -f $f -c $container_name -d $local_db -U $db_user - done - else - echo "Okay, your choice..." - exit 1; -fi \ No newline at end of file + +for file in `dirname $0`/../db-alterations/*.sql +do + `dirname $0`/./run-sql-file -f $file -c $container_name -d $local_db -U $db_user +done +for f in `dirname $0`/../fixtures/*.sql +do + `dirname $0`/./run-sql-file -f $f -c $container_name -d $local_db -U $db_user +done diff --git a/v2-transition/services/column-builder/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/database/fixtures/02-auth.sql index 3097b9dfc..93080c216 100644 --- a/v2-transition/services/column-builder/database/fixtures/02-auth.sql +++ b/v2-transition/services/column-builder/database/fixtures/02-auth.sql @@ -39,6 +39,8 @@ CREATE EXTENSION IF NOT EXISTS pgjwt; CREATE TABLE IF NOT EXISTS auth.users( id serial primary key, + firstname text not null, + lastname text not null, username text not null, pass text not null check (length(pass) < 512), role name not null check (length(role) < 512) @@ -149,12 +151,13 @@ END $$ language plpgsql SECURITY DEFINER; CREATE OR REPLACE FUNCTION -macrostrat_api.create_user(username text, pass text) RETURNS BOOLEAN AS $$ +macrostrat_api.create_user(username text, firstName text, lastName text, pass text) +RETURNS BOOLEAN AS $$ DECLARE _role name; BEGIN - INSERT INTO auth.users(username, pass, role) - VALUES (username, pass, 'api_user'); + INSERT INTO auth.users(username, firstname, lastname, pass, role) + VALUES (username, firstName, lastName, pass, 'api_user'); SELECT auth.user_role(username, pass) INTO _role; IF _role IS NULL THEN @@ -178,9 +181,9 @@ GRANT USAGE ON SCHEMA macrostrat_api TO anon; GRANT USAGE ON SCHEMA macrostrat_api TO authenticator; GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; -GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text,text,text, text) TO anon; GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator; -GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO authenticator; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text,text,text, text) TO authenticator; -- a general api_user, data privileges depend on RLS GRANT USAGE ON SCHEMA auth TO api_user; From 3b12cb6b5ac8b0b24077ffe819c3ab0a04cf9850 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Thu, 7 Apr 2022 16:41:54 +0200 Subject: [PATCH 09/13] create user takes name --- .../services/column-builder/database/fixtures/02-auth.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v2-transition/services/column-builder/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/database/fixtures/02-auth.sql index 93080c216..7c344d80d 100644 --- a/v2-transition/services/column-builder/database/fixtures/02-auth.sql +++ b/v2-transition/services/column-builder/database/fixtures/02-auth.sql @@ -151,7 +151,7 @@ END $$ language plpgsql SECURITY DEFINER; CREATE OR REPLACE FUNCTION -macrostrat_api.create_user(username text, firstName text, lastName text, pass text) +macrostrat_api.create_user(firstname text, lastname text, pass text, username text) RETURNS BOOLEAN AS $$ DECLARE _role name; From d9613efa334fcb62bea1a229fc5c903657f8e863 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Tue, 12 Apr 2022 17:18:58 +0200 Subject: [PATCH 10/13] new testing auth schema and roles --- .../column-builder/backend/bin/run-tests | 4 +- .../backend/tests/test_z_auth.py | 53 +++++---- .../fixtures/{auth.sql => 02-auth.sql} | 105 +++++++----------- .../database/fixtures/02-auth.sql | 4 +- 4 files changed, 77 insertions(+), 89 deletions(-) rename v2-transition/services/column-builder/backend/urvogel/database/fixtures/{auth.sql => 02-auth.sql} (74%) diff --git a/v2-transition/services/column-builder/backend/bin/run-tests b/v2-transition/services/column-builder/backend/bin/run-tests index 8f0369af4..8b08ed6bd 100755 --- a/v2-transition/services/column-builder/backend/bin/run-tests +++ b/v2-transition/services/column-builder/backend/bin/run-tests @@ -8,10 +8,10 @@ result=$( docker ps -q -f name=postgrest ) if [[ -n "$result" ]]; then echo "Rebuilding Postgrest Docker container for testing!" - POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon PGUSER=authenticator docker-compose up -d --build postgrest + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon_test AUTH_PGUSER=authenticator_test docker-compose up -d --build postgrest else echo "Starting Docker" - POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon PGUSER=authenticator docker-compose up -d + POSTGRES_DB=col_test PGRST_DB_ANON_ROLE=anon_test AUTH_PGUSER=authenticator_test docker-compose up -d --build postgrest fi pytest --pdb diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 907d415c8..0b92f1d4b 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -1,15 +1,16 @@ from requests import get, post, patch, put from urvogel.database.fixtures import get_sql +import time base= "http://127.0.0.1:3001" -auth = get_sql("auth.sql") -auth_inserts = get_sql("test_auth_inserts.sql") -email = "cidzikowski@wisc.edu" +username = "cidzikowski" password = "gniessrocks" -def login(email, password): - res = post(base+"/rpc/login", data={"email": email, "pass": password}) +auth = get_sql("02-auth.sql") + +def login(username, password): + res = post(base+"/rpc/login", data={"username": username, "pass": password}) token = res.json().get('token') headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} @@ -34,7 +35,7 @@ def test_create_auth(db): res = db.query(sql).fetchall() for row in res: - assert row.get('rolname') in ['api_views_owner','anon','authenticator', 'api_user'] + assert row.get('rolname') in ['api_views_owner','anon','authenticator','anon_test','authenticator_test', 'api_user'] def test_pg_extensions(db): sql = """ select extname from pg_extension; """ @@ -44,21 +45,21 @@ def test_pg_extensions(db): assert 'pgjwt' in extensions def test_add_user(db): - #assert 0 == 1 - params = {"email": email, "pass": password} + time.sleep(10) # if I don't wait it all fails. As if the sql is still being run.... + params = {"firstname": "Casey", "lastname": "Idzikowski", "pass": password, "username": username} res = post(base+"/rpc/create_user", data=params) assert res.status_code == 200 sql = """ - SELECT email from auth.users; + SELECT username from auth.users; """ res = db.query(sql).fetchone() - assert res.get('email') is not None + assert res.get('username') is not None def test_login(db): - res = post(base+"/rpc/login", data={"email": email, "pass": password}) + res = post(base+"/rpc/login", data={"username": username, "pass": password}) assert res.status_code == 200 @@ -66,9 +67,9 @@ def test_login(db): assert token is not None headers = {"Prefer": "return=representation", "Authorization": f'bearer {token}'} - res = post(base + "/rpc/get_email", headers=headers) + res = post(base + "/rpc/get_username", headers=headers) - assert res.json() == email + assert res.json() == username res = get(base + "/projects", headers=headers) data = res.json() @@ -91,7 +92,7 @@ def test_login(db): assert len(data) == 1 and data[0].get('id') == 1 def test_project_create(db): - res = post(base+"/rpc/login", data={"email": email, "pass": password}) + res = post(base+"/rpc/login", data={"username": username, "pass": password}) assert res.status_code == 200 @@ -109,7 +110,7 @@ def test_project_create(db): def test_child_data(db): """ add some col-group, col and unit and see that we can access it """ - headers = login(email, password) + headers = login(username, password) col_group = {"col_group": "CG1", "col_group_long": "Casey's first fake column group", "project_id":13} res = post(base+"/col_groups", data=col_group, headers=headers) @@ -124,9 +125,9 @@ def test_rls(db): create a new user with read only access to casey's project, As owner I should be able to configure user privileges """ - email = 'app_user@gmail.com' + username = 'app_user@gmail.com' password = 'appuser1' - params = {"email": email, "pass": password} + params = {'firstname': 'appuser','lastname':'lastnameApp',"username": username, "pass": password} res = post(base+"/rpc/create_user", data=params) @@ -138,9 +139,18 @@ def test_rls(db): assert len(data) == 0 + res = post(base + "/projects", headers=headers, data={"project":"app1", "descrip":"fake project created and owned by app", "timescale_id": 1}) + + assert res.status_code == 201 + res = get(base + "/projects", headers=headers) + data = res.json() + + assert len(data) == 1 + + def test_user_management(): """ """ - headers = login(email,password) + headers = login(username,password) res = get(base + "/user_projects", headers=headers) @@ -148,7 +158,7 @@ def test_user_management(): headers_ = login('app_user@gmail.com', 'appuser1') res = get(base + "/user_projects", headers=headers_) - assert len(res.json()) == 0 + assert len(res.json()) == 1 # make app_user a reader for project 13 data = {"user_":2, "project":13, "role_id": 1 } @@ -158,6 +168,5 @@ def test_user_management(): res = get(base + "/projects", headers=headers_) data = res.json() - assert len(data) == 1 - assert data[0].get('id') == 13 - assert 0 ==1 \ No newline at end of file + assert len(data) == 2 + assert data[0].get('id') == 13 \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql similarity index 74% rename from v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql rename to v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql index 0f735b688..afcb69ad6 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql @@ -2,37 +2,14 @@ Postgrest uses JWT to authenticate incoming requests, but the db can authorize db queries based on users. -Postgrest has a db centered system for handling incoming requests. A limited db role called 'authenticator' has -the job to decrypt the incoming JWT and if correct, authenticator switches into the specified db role sent -in the request. If not correct, authenticator switces to 'anon' another db role that should be very limited. -With only the ability to login, or create a new user. Setting the names of anon and authenticator is done in -a configuration file. The JWT secret for decoding must also be provided in the config. authenticator is passed via db-uri anon: db-anon-role (PGRST_DB_ANON_ROLE) jwt-secret (PGRST_JWT_SECRET) -anon and authenticator must be privelges must be configured in db by superuser. - -In access control there is a distinction between application users and db users. Application users can -be thought of as your client users logging in and may be in the thousands or more. db users are the ROLEs -that can be created and inherited. - -For our purposes we can combine both. We will map app users to db users in a general way. But we will also -keep track of the projects, col, units, etc, that users can "SELECT, UPDATE, INSERT, DELETE". Generally, these -will be things that the user creates themselves. But they should also be able to give permissions to other users. - -General DB roles: - -Handle users in-database: - -auth schema, users table -keep track of project ids that user can view data for in table. -Configure row level security by policies on table. - HOW LOGIN WORKS --> { - take email and password, + take username and password, get the role and any other info we want tokenized, if login successful --> return json token } @@ -43,14 +20,13 @@ https://app.bountysource.com/issues/89971002-example-code-to-show-how-to-install How to access info on JWT for the current user --> to be user in policy creation:: -current_setting('request.jwt.claims', true)::json->>'email'; +current_setting('request.jwt.claims', true)::json->>'username'; */ - /* AUTH schema and functions */ -DROP SCHEMA auth CASCADE; +DROP SCHEMA IF EXISTS auth CASCADE; CREATE SCHEMA auth; @@ -62,7 +38,9 @@ CREATE EXTENSION IF NOT EXISTS pgjwt; CREATE TABLE IF NOT EXISTS auth.users( id serial primary key, - email text check ( email ~* '^.+@.+\..+$' ), + firstname text not null, + lastname text not null, + username text not null, pass text not null check (length(pass) < 512), role name not null check (length(role) < 512) ); @@ -129,13 +107,13 @@ CREATE trigger encrypt_pass /* Access the stored role on a user -- used in login! */ CREATE OR REPLACE FUNCTION -auth.user_role(email TEXT, pass TEXT) RETURNS name +auth.user_role(username TEXT, pass TEXT) RETURNS name LANGUAGE plpgsql AS $$ BEGIN RETURN ( SELECT role FROM auth.users - WHERE users.email = user_role.email + WHERE users.username = user_role.username AND users.pass = public.crypt(user_role.pass, users.pass) ); END; @@ -149,12 +127,12 @@ CREATE TYPE auth.jwt_token AS ( Login function! */ CREATE OR REPLACE FUNCTION -macrostrat_api.login(email text, pass text) RETURNS auth.jwt_token AS $$ +macrostrat_api.login(username text, pass text) RETURNS auth.jwt_token AS $$ DECLARE _role name; result auth.jwt_token; BEGIN - SELECT auth.user_role(email, pass) INTO _role; + SELECT auth.user_role(username, pass) INTO _role; IF _role IS NULL THEN raise invalid_password using message = 'invalid user or password'; END IF; @@ -163,7 +141,7 @@ BEGIN row_to_json(r), 'reallyreallyreallyreallyverysafesafesafesafe' ) AS token FROM ( - SELECT 'api_views_owner' as role, login.email as email, + SELECT 'api_views_owner' as role, login.username as username, extract(epoch FROM now())::integer + 86400 AS exp --expires in 1 day ) r INTO result; @@ -172,13 +150,14 @@ END $$ language plpgsql SECURITY DEFINER; CREATE OR REPLACE FUNCTION -macrostrat_api.create_user(email text, pass text) RETURNS BOOLEAN AS $$ +macrostrat_api.create_user(firstname text, lastname text, pass text, username text) +RETURNS BOOLEAN AS $$ DECLARE _role name; BEGIN - INSERT INTO auth.users(email, pass, role) - VALUES (email, pass, 'api_views_owner'); - SELECT auth.user_role(email, pass) INTO _role; + INSERT INTO auth.users(username, firstname, lastname, pass, role) + VALUES (username, firstname, lastname, pass, 'api_views_owner'); + SELECT auth.user_role(username, pass) INTO _role; IF _role IS NULL THEN RETURN FALSE; @@ -191,51 +170,51 @@ $$ language plpgsql SECURITY DEFINER; /*####################### BASE DB ROLES ##########################*/ -- these are the basic auth roles used by postgrest. -DROP ROLE IF EXISTS anon; -CREATE ROLE anon NOINHERIT; -DROP ROLE IF EXISTS authenticator; -CREATE ROLE authenticator NOINHERIT LOGIN; -GRANT anon TO authenticator; +DROP ROLE IF EXISTS anon_test; +CREATE ROLE anon_test NOINHERIT; +DROP ROLE IF EXISTS authenticator_test; +CREATE ROLE authenticator_test NOINHERIT LOGIN; +GRANT anon_test TO authenticator_test; -GRANT USAGE ON SCHEMA macrostrat_api TO anon; -GRANT USAGE ON SCHEMA macrostrat_api TO authenticator; +GRANT USAGE ON SCHEMA macrostrat_api TO anon_test; +GRANT USAGE ON SCHEMA macrostrat_api TO authenticator_test; -GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon; -GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO anon; -GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator; -GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text, text) TO authenticator; +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO anon_test; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text,text,text, text) TO anon_test; +GRANT EXECUTE ON FUNCTION macrostrat_api.login(text,text) TO authenticator_test; +GRANT EXECUTE ON FUNCTION macrostrat_api.create_user(text,text,text, text) TO authenticator_test; --- a general api_user, data privileges depend on RLS +-- a general api_views_owner, data privileges depend on RLS GRANT USAGE ON SCHEMA auth TO api_views_owner; GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA auth TO api_views_owner; GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA auth TO api_views_owner; -GRANT api_views_owner to authenticator; +GRANT api_views_owner to authenticator_test; /* ################### Row level policies ################### */ -/* function to get email off of jwt claims*/ +/* function to get username off of jwt claims*/ CREATE OR REPLACE FUNCTION -macrostrat_api.get_email() returns text AS $$ +macrostrat_api.get_username() returns text AS $$ DECLARE - email_ text; + username_ text; BEGIN - SELECT current_setting('request.jwt.claims', true)::json->>'email' INTO email_; -RETURN email_; + SELECT current_setting('request.jwt.claims', true)::json->>'username' INTO username_; +RETURN username_; END $$language plpgsql SECURITY DEFINER; CREATE OR REPLACE FUNCTION auth.user_project_insert() RETURNS trigger AS $$ DECLARE - email_ text; + username_ text; id_ int; manager_id int; BEGIN IF tg_op = 'INSERT' THEN - select macrostrat_api.get_email() into email_; - select id from auth.users where users.email = email_ INTO id_; + select macrostrat_api.get_username() into username_; + select id from auth.users where users.username = username_ INTO id_; SELECT id FROM auth.data_roles WHERE role = 'manager' INTO manager_id; INSERT INTO auth.user_projects(user_, project, role_id) VALUES(id_, new.id, manager_id); @@ -254,16 +233,16 @@ CREATE OR REPLACE FUNCTION macrostrat_api.current_user_projects() RETURNS TABLE (project integer, role text) AS $$ DECLARE - email_ text; + username_ text; BEGIN - SELECT macrostrat_api.get_email() INTO email_; + SELECT macrostrat_api.get_username() INTO username_; RETURN QUERY SELECT up.project, adr.role FROM auth.user_projects up JOIN auth.users u on u.id = up.user_ JOIN auth.data_roles adr ON adr.id = up.role_id - WHERE u.email = email_; + WHERE u.username = username_; END $$ language plpgsql SECURITY DEFINER; @@ -271,8 +250,8 @@ $$ language plpgsql SECURITY DEFINER; ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY; CREATE POLICY secure_users ON auth.users -USING (email = macrostrat_api.get_email()) -WITH CHECK (email = macrostrat_api.get_email()); +USING (username = macrostrat_api.get_username()) +WITH CHECK (username = macrostrat_api.get_username()); /* user_projects mapping tables */ ALTER TABLE auth.user_projects ENABLE ROW LEVEL SECURITY; diff --git a/v2-transition/services/column-builder/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/database/fixtures/02-auth.sql index 7c344d80d..f24e5c46e 100644 --- a/v2-transition/services/column-builder/database/fixtures/02-auth.sql +++ b/v2-transition/services/column-builder/database/fixtures/02-auth.sql @@ -27,7 +27,7 @@ current_setting('request.jwt.claims', true)::json->>'username'; /* AUTH schema and functions */ -DROP SCHEMA auth CASCADE; +DROP SCHEMA IF EXISTS auth CASCADE; CREATE SCHEMA auth; @@ -157,7 +157,7 @@ DECLARE _role name; BEGIN INSERT INTO auth.users(username, firstname, lastname, pass, role) - VALUES (username, firstName, lastName, pass, 'api_user'); + VALUES (username, firstname, lastname, pass, 'api_user'); SELECT auth.user_role(username, pass) INTO _role; IF _role IS NULL THEN From 99e260457bc17f1e7e8f785e1934769a715b5500 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Tue, 12 Apr 2022 17:19:16 +0200 Subject: [PATCH 11/13] more env variables... --- v2-transition/services/column-builder/docker-compose.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2-transition/services/column-builder/docker-compose.yaml b/v2-transition/services/column-builder/docker-compose.yaml index 5a0156f27..90790005f 100644 --- a/v2-transition/services/column-builder/docker-compose.yaml +++ b/v2-transition/services/column-builder/docker-compose.yaml @@ -13,10 +13,10 @@ services: ports: - "3001:3000" environment: - PGRST_DB_URI: postgres://authenticator:@db:5432/column_data_auth + PGRST_DB_URI: postgres://${AUTH_PGUSER}:@db:5432/${POSTGRES_DB} PGRST_DB_SCHEMA: macrostrat_api PGRST_JWT_SECRET: ${PGRST_JWT_SECRET} - PGRST_DB_ANON_ROLE: anon + PGRST_DB_ANON_ROLE: ${PGRST_DB_ANON_ROLE} PGRST_OPENAPI_SERVER_PROXY_URI: http://127.0.0.1:3001 depends_on: - db From 8d451c9e94112509ae6c037abd125c94b7b948f4 Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Tue, 12 Apr 2022 17:19:28 +0200 Subject: [PATCH 12/13] script to dump auth schema --- .../urvogel/database/bin/dump-auth-schema | 11 + .../database/fixtures/auth_schema_dump.sql | 5419 +++++++++++++++++ 2 files changed, 5430 insertions(+) create mode 100755 v2-transition/services/column-builder/backend/urvogel/database/bin/dump-auth-schema create mode 100644 v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth_schema_dump.sql diff --git a/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-auth-schema b/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-auth-schema new file mode 100755 index 000000000..74ffcc1cf --- /dev/null +++ b/v2-transition/services/column-builder/backend/urvogel/database/bin/dump-auth-schema @@ -0,0 +1,11 @@ +#!/usr/bin/env zsh + +#### Basically same as dump-schema, but for the db with auth schema + +echo "Removing old schema dump if it exists!!" +rm -f `dirname $0`/../fixtures/auth_schema_dump.sql + +echo "" +echo "" +echo "Dumping the new schema" +docker-compose exec db pg_dump -s -U postgres -d column_data_auth > `dirname $0`/../fixtures/auth_schema_dump.sql \ No newline at end of file diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth_schema_dump.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth_schema_dump.sql new file mode 100644 index 000000000..d818ae221 --- /dev/null +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/auth_schema_dump.sql @@ -0,0 +1,5419 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 14.1 (Debian 14.1-1.pgdg110+1) +-- Dumped by pg_dump version 14.1 (Debian 14.1-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: auth; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA auth; + + +ALTER SCHEMA auth OWNER TO postgres; + +-- +-- Name: macrostrat; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA macrostrat; + + +ALTER SCHEMA macrostrat OWNER TO postgres; + +-- +-- Name: macrostrat_api; Type: SCHEMA; Schema: -; Owner: postgres +-- + +CREATE SCHEMA macrostrat_api; + + +ALTER SCHEMA macrostrat_api OWNER TO postgres; + +-- +-- Name: pgcrypto; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pgcrypto WITH SCHEMA public; + + +-- +-- Name: EXTENSION pgcrypto; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION pgcrypto IS 'cryptographic functions'; + + +-- +-- Name: pgjwt; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS pgjwt WITH SCHEMA public; + + +-- +-- Name: EXTENSION pgjwt; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION pgjwt IS 'JSON Web Token API for Postgresql'; + + +-- +-- 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 and geography spatial types and functions'; + + +-- +-- Name: jwt_token; Type: TYPE; Schema: auth; Owner: postgres +-- + +CREATE TYPE auth.jwt_token AS ( + token text +); + + +ALTER TYPE auth.jwt_token OWNER TO postgres; + +-- +-- Name: measurement_class; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.measurement_class AS ENUM ( + '', + 'geophysical', + 'geochemical', + 'sedimentological' +); + + +ALTER TYPE public.measurement_class OWNER TO postgres; + +-- +-- Name: measurement_type; Type: TYPE; Schema: public; Owner: postgres +-- + +CREATE TYPE public.measurement_type AS ENUM ( + '', + 'material properties', + 'geochronological', + 'major elements', + 'minor elements', + 'radiogenic isotopes', + 'stable isotopes', + 'petrologic', + 'environmental' +); + + +ALTER TYPE public.measurement_type OWNER TO postgres; + +-- +-- Name: check_role_exists(); Type: FUNCTION; Schema: auth; Owner: postgres +-- + +CREATE FUNCTION auth.check_role_exists() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles AS r WHERE r.rolname = new.role) THEN + raise foreign_key_violation USING message = + 'unknown database role: ' || new.role; + RETURN NULL; + END IF; + RETURN new; +END +$$; + + +ALTER FUNCTION auth.check_role_exists() OWNER TO postgres; + +-- +-- Name: encrypt_pass(); Type: FUNCTION; Schema: auth; Owner: postgres +-- + +CREATE FUNCTION auth.encrypt_pass() RETURNS trigger + LANGUAGE plpgsql + AS $$ +BEGIN + IF tg_op = 'INSERT' OR new.pass <> old.pass THEN + new.pass := public.crypt(new.pass, public.gen_salt('md5')); + END IF; + RETURN new; +END +$$; + + +ALTER FUNCTION auth.encrypt_pass() OWNER TO postgres; + +-- +-- Name: user_project_insert(); Type: FUNCTION; Schema: auth; Owner: postgres +-- + +CREATE FUNCTION auth.user_project_insert() RETURNS trigger + LANGUAGE plpgsql SECURITY DEFINER + AS $$ +DECLARE + username_ text; + id_ int; + manager_id int; +BEGIN + IF tg_op = 'INSERT' THEN + select macrostrat_api.get_username() into username_; + select id from auth.users where users.username = username_ INTO id_; + SELECT id FROM auth.data_roles WHERE role = 'manager' INTO manager_id; + INSERT INTO auth.user_projects(user_, project, role_id) + VALUES(id_, new.id, manager_id); + END IF; + RETURN new; +END +$$; + + +ALTER FUNCTION auth.user_project_insert() OWNER TO postgres; + +-- +-- Name: user_role(text, text); Type: FUNCTION; Schema: auth; Owner: postgres +-- + +CREATE FUNCTION auth.user_role(username text, pass text) RETURNS name + LANGUAGE plpgsql + AS $$ +BEGIN + RETURN ( + SELECT role FROM auth.users + WHERE users.username = user_role.username + AND users.pass = public.crypt(user_role.pass, users.pass) + ); +END; +$$; + + +ALTER FUNCTION auth.user_role(username text, pass text) OWNER TO postgres; + +-- +-- Name: make_into_serial(text, text); Type: FUNCTION; Schema: macrostrat; Owner: postgres +-- + +CREATE FUNCTION macrostrat.make_into_serial(table_name text, column_name text) RETURNS integer + LANGUAGE plpgsql + AS $$ +DECLARE + start_with INTEGER; + sequence_name TEXT; +BEGIN + sequence_name := table_name || '_' || column_name || '_seq'; + EXECUTE 'SELECT coalesce(max(' || column_name || '), 0) + 1 FROM ' || table_name + INTO start_with; + EXECUTE 'CREATE SEQUENCE IF NOT EXISTS ' || sequence_name || + ' START WITH ' || start_with || + ' OWNED BY ' || table_name || '.' || column_name; + EXECUTE 'SELECT setval(' || quote_literal(sequence_name)|| ',' || start_with || ') FROM ' || table_name; + EXECUTE 'ALTER TABLE ' || table_name || ' ALTER COLUMN ' || column_name || + ' SET DEFAULT nextVal(''' || sequence_name || ''')'; + RETURN start_with; +END; +$$; + + +ALTER FUNCTION macrostrat.make_into_serial(table_name text, column_name text) OWNER TO postgres; + +-- +-- Name: pg_reset_pkey_seq(); Type: PROCEDURE; Schema: macrostrat; Owner: postgres +-- + +CREATE PROCEDURE macrostrat.pg_reset_pkey_seq() + LANGUAGE plpgsql + AS $_$ +DECLARE + sql_reset TEXT; + table_pkeys RECORD; + next_val INT; +BEGIN + +sql_reset := +$sql$ +SELECT macrostrat.make_into_serial('%1$s.%2$s', '%3$s'); +$sql$; + +FOR table_pkeys IN + SELECT kcu.table_schema, kcu.table_name, kcu.column_name + FROM information_schema.key_column_usage kcu + JOIN information_schema.table_constraints tc + ON tc.constraint_name = kcu.constraint_name + WHERE tc.constraint_type='PRIMARY KEY' + AND kcu.table_schema='macrostrat' +LOOP + EXECUTE format(sql_reset, table_pkeys.table_schema,table_pkeys.table_name,table_pkeys.column_name) INTO next_val; + RAISE info 'Resetting Sequence for: %.% (%) to %' + , table_pkeys.table_schema + , table_pkeys.table_name + , table_pkeys.column_name + , next_val + ; +END LOOP; +END +$_$; + + +ALTER PROCEDURE macrostrat.pg_reset_pkey_seq() OWNER TO postgres; + +-- +-- Name: create_user(text, text, text, text); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- + +CREATE FUNCTION macrostrat_api.create_user(firstname text, lastname text, pass text, username text) RETURNS boolean + LANGUAGE plpgsql SECURITY DEFINER + AS $$ +DECLARE + _role name; +BEGIN + INSERT INTO auth.users(username, firstname, lastname, pass, role) + VALUES (username, firstName, lastName, pass, 'api_user'); + SELECT auth.user_role(username, pass) INTO _role; + + IF _role IS NULL THEN + RETURN FALSE; + END IF; + + RETURN TRUE; +END +$$; + + +ALTER FUNCTION macrostrat_api.create_user(firstname text, lastname text, pass text, username text) OWNER TO postgres; + +-- +-- Name: current_user_projects(); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- + +CREATE FUNCTION macrostrat_api.current_user_projects() RETURNS TABLE(project integer, role text) + LANGUAGE plpgsql SECURITY DEFINER + AS $$ +DECLARE + username_ text; +BEGIN + SELECT macrostrat_api.get_username() INTO username_; + RETURN QUERY + SELECT up.project, adr.role FROM auth.user_projects up + JOIN auth.users u + on u.id = up.user_ + JOIN auth.data_roles adr + ON adr.id = up.role_id + WHERE u.username = username_; +END +$$; + + +ALTER FUNCTION macrostrat_api.current_user_projects() OWNER TO postgres; + +-- +-- Name: get_username(); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- + +CREATE FUNCTION macrostrat_api.get_username() RETURNS text + LANGUAGE plpgsql SECURITY DEFINER + AS $$ +DECLARE + username_ text; +BEGIN + SELECT current_setting('request.jwt.claims', true)::json->>'username' INTO username_; +RETURN username_; +END +$$; + + +ALTER FUNCTION macrostrat_api.get_username() OWNER TO postgres; + +-- +-- Name: login(text, text); Type: FUNCTION; Schema: macrostrat_api; Owner: postgres +-- + +CREATE FUNCTION macrostrat_api.login(username text, pass text) RETURNS auth.jwt_token + LANGUAGE plpgsql SECURITY DEFINER + AS $$ +DECLARE + _role name; + result auth.jwt_token; +BEGIN + SELECT auth.user_role(username, pass) INTO _role; + IF _role IS NULL THEN + raise invalid_password using message = 'invalid user or password'; + END IF; + -- sign function comes from pgjwt extension. + SELECT sign( + row_to_json(r), 'reallyreallyreallyreallyverysafesafesafesafe' + ) AS token + FROM ( + SELECT 'api_user' as role, login.username as username, + extract(epoch FROM now())::integer + 86400 AS exp --expires in 1 day + ) r + INTO result; + RETURN result; +END +$$; + + +ALTER FUNCTION macrostrat_api.login(username text, pass text) OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: data_roles; Type: TABLE; Schema: auth; Owner: postgres +-- + +CREATE TABLE auth.data_roles ( + id integer NOT NULL, + role text, + description text +); + + +ALTER TABLE auth.data_roles OWNER TO postgres; + +-- +-- Name: data_roles_id_seq; Type: SEQUENCE; Schema: auth; Owner: postgres +-- + +CREATE SEQUENCE auth.data_roles_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE auth.data_roles_id_seq OWNER TO postgres; + +-- +-- Name: data_roles_id_seq; Type: SEQUENCE OWNED BY; Schema: auth; Owner: postgres +-- + +ALTER SEQUENCE auth.data_roles_id_seq OWNED BY auth.data_roles.id; + + +-- +-- Name: user_projects; Type: TABLE; Schema: auth; Owner: postgres +-- + +CREATE TABLE auth.user_projects ( + id integer NOT NULL, + user_ integer, + project integer, + role_id integer +); + + +ALTER TABLE auth.user_projects OWNER TO postgres; + +-- +-- Name: user_projects_id_seq; Type: SEQUENCE; Schema: auth; Owner: postgres +-- + +CREATE SEQUENCE auth.user_projects_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE auth.user_projects_id_seq OWNER TO postgres; + +-- +-- Name: user_projects_id_seq; Type: SEQUENCE OWNED BY; Schema: auth; Owner: postgres +-- + +ALTER SEQUENCE auth.user_projects_id_seq OWNED BY auth.user_projects.id; + + +-- +-- Name: users; Type: TABLE; Schema: auth; Owner: postgres +-- + +CREATE TABLE auth.users ( + id integer NOT NULL, + firstname text NOT NULL, + lastname text NOT NULL, + username text NOT NULL, + pass text NOT NULL, + role name NOT NULL, + CONSTRAINT users_pass_check CHECK ((length(pass) < 512)), + CONSTRAINT users_role_check CHECK ((length((role)::text) < 512)) +); + + +ALTER TABLE auth.users OWNER TO postgres; + +-- +-- Name: users_id_seq; Type: SEQUENCE; Schema: auth; Owner: postgres +-- + +CREATE SEQUENCE auth.users_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE auth.users_id_seq OWNER TO postgres; + +-- +-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: auth; Owner: postgres +-- + +ALTER SEQUENCE auth.users_id_seq OWNED BY auth.users.id; + + +-- +-- Name: autocomplete; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.autocomplete ( + id integer NOT NULL, + name text, + type text, + category text +); + + +ALTER TABLE macrostrat.autocomplete OWNER TO postgres; + +-- +-- Name: TABLE autocomplete; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.autocomplete IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: col_areas; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.col_areas ( + id integer NOT NULL, + col_id integer, + col_area public.geometry, + wkt text +); + + +ALTER TABLE macrostrat.col_areas OWNER TO postgres; + +-- +-- Name: TABLE col_areas; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.col_areas IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: col_areas_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.col_areas_id_seq + START WITH 5355 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.col_areas_id_seq OWNER TO postgres; + +-- +-- Name: col_areas_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.col_areas_id_seq OWNED BY macrostrat.col_areas.id; + + +-- +-- Name: col_groups; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.col_groups ( + id integer NOT NULL, + col_group character varying(100), + col_group_long character varying(100), + project_id integer +); + + +ALTER TABLE macrostrat.col_groups OWNER TO postgres; + +-- +-- Name: TABLE col_groups; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.col_groups IS 'Last updated from MariaDB - 2021-08-30 11:28'; + + +-- +-- Name: col_groups_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.col_groups_id_seq + START WITH 354 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.col_groups_id_seq OWNER TO postgres; + +-- +-- Name: col_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.col_groups_id_seq OWNED BY macrostrat.col_groups.id; + + +-- +-- Name: col_refs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.col_refs ( + id integer NOT NULL, + col_id integer, + ref_id integer +); + + +ALTER TABLE macrostrat.col_refs OWNER TO postgres; + +-- +-- Name: TABLE col_refs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.col_refs IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: col_refs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.col_refs_id_seq + START WITH 9721 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.col_refs_id_seq OWNER TO postgres; + +-- +-- Name: col_refs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.col_refs_id_seq OWNED BY macrostrat.col_refs.id; + + +-- +-- Name: cols; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.cols ( + id integer NOT NULL, + col_group_id smallint, + project_id smallint, + col_type text, + status_code character varying(25), + col_position character varying(25), + col numeric, + col_name character varying(100), + lat numeric, + lng numeric, + col_area numeric, + coordinate public.geometry, + wkt text, + created text, + poly_geom public.geometry, + notes text +); + + +ALTER TABLE macrostrat.cols OWNER TO postgres; + +-- +-- Name: TABLE cols; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.cols IS 'Last updated from MariaDB - 2022-02-25 14:47'; + + +-- +-- Name: cols_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.cols_id_seq + START WITH 5728 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.cols_id_seq OWNER TO postgres; + +-- +-- Name: cols_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.cols_id_seq OWNED BY macrostrat.cols.id; + + +-- +-- Name: concepts_places; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.concepts_places ( + concept_id integer NOT NULL, + place_id integer NOT NULL +); + + +ALTER TABLE macrostrat.concepts_places OWNER TO postgres; + +-- +-- Name: TABLE concepts_places; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.concepts_places IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: econs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.econs ( + id integer NOT NULL, + econ text, + econ_type text, + econ_class text, + econ_color text +); + + +ALTER TABLE macrostrat.econs OWNER TO postgres; + +-- +-- Name: TABLE econs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.econs IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: econs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.econs_id_seq + START WITH 24 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.econs_id_seq OWNER TO postgres; + +-- +-- Name: econs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.econs_id_seq OWNED BY macrostrat.econs.id; + + +-- +-- Name: environs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.environs ( + id integer NOT NULL, + environ text, + environ_type text, + environ_class text, + environ_color text +); + + +ALTER TABLE macrostrat.environs OWNER TO postgres; + +-- +-- Name: TABLE environs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.environs IS 'Last updated from MariaDB - 2021-08-30 11:30'; + + +-- +-- Name: environs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.environs_id_seq + START WITH 94 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.environs_id_seq OWNER TO postgres; + +-- +-- Name: environs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.environs_id_seq OWNED BY macrostrat.environs.id; + + +-- +-- Name: grainsize; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.grainsize ( + grain_id integer NOT NULL, + grain_symbol text, + grain_name text, + grain_group text, + soil_group text, + min_size numeric, + max_size numeric, + classification text +); + + +ALTER TABLE macrostrat.grainsize OWNER TO postgres; + +-- +-- Name: grainsize_grain_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.grainsize_grain_id_seq + START WITH 32 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.grainsize_grain_id_seq OWNER TO postgres; + +-- +-- Name: grainsize_grain_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.grainsize_grain_id_seq OWNED BY macrostrat.grainsize.grain_id; + + +-- +-- Name: intervals; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.intervals ( + id integer NOT NULL, + age_bottom numeric, + age_top numeric, + interval_name character varying(200), + interval_abbrev character varying(50), + interval_type character varying(50), + interval_color character varying(20), + rank integer +); + + +ALTER TABLE macrostrat.intervals OWNER TO postgres; + +-- +-- Name: TABLE intervals; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.intervals IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: intervals_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.intervals_id_seq + START WITH 1596 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.intervals_id_seq OWNER TO postgres; + +-- +-- Name: intervals_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.intervals_id_seq OWNED BY macrostrat.intervals.id; + + +-- +-- Name: intervals_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.intervals_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.intervals_new_id_seq OWNER TO postgres; + +-- +-- Name: intervals_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.intervals_new_id_seq OWNED BY macrostrat.intervals.id; + + +-- +-- Name: lith_atts; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lith_atts ( + id integer NOT NULL, + lith_att character varying(75), + att_type character varying(25), + lith_att_fill integer +); + + +ALTER TABLE macrostrat.lith_atts OWNER TO postgres; + +-- +-- Name: TABLE lith_atts; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lith_atts IS 'Last updated from MariaDB - 2021-08-30 11:26'; + + +-- +-- Name: lith_atts_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.lith_atts_id_seq + START WITH 186 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.lith_atts_id_seq OWNER TO postgres; + +-- +-- Name: lith_atts_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.lith_atts_id_seq OWNED BY macrostrat.lith_atts.id; + + +-- +-- Name: liths; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.liths ( + id integer NOT NULL, + lith character varying(75), + lith_group text, + lith_type character varying(50), + lith_class character varying(50), + lith_equiv integer, + lith_fill integer, + comp_coef numeric, + initial_porosity numeric, + bulk_density numeric, + lith_color character varying(12) +); + + +ALTER TABLE macrostrat.liths OWNER TO postgres; + +-- +-- Name: TABLE liths; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: liths_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.liths_id_seq + START WITH 207 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.liths_id_seq OWNER TO postgres; + +-- +-- Name: liths_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.liths_id_seq OWNED BY macrostrat.liths.id; + + +-- +-- Name: lookup_strat_names; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lookup_strat_names ( + strat_name_id integer, + strat_name character varying(100), + rank character varying(20), + concept_id integer, + rank_name character varying(200), + bed_id integer, + bed_name character varying(100), + mbr_id integer, + mbr_name character varying(100), + fm_id integer, + fm_name character varying(100), + gp_id integer, + gp_name character varying(100), + sgp_id integer, + sgp_name character varying(100), + early_age numeric, + late_age numeric, + gsc_lexicon character varying(20), + b_period character varying(100), + t_period character varying(100), + c_interval character varying(100), + name_no_lith character varying(100) +); + + +ALTER TABLE macrostrat.lookup_strat_names OWNER TO postgres; + +-- +-- Name: TABLE lookup_strat_names; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lookup_strat_names IS 'Last updated from MariaDB - 2021-08-30 11:59'; + + +-- +-- Name: lookup_unit_attrs_api; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lookup_unit_attrs_api ( + unit_id integer, + lith json, + environ json, + econ json, + measure_short json, + measure_long json +); + + +ALTER TABLE macrostrat.lookup_unit_attrs_api OWNER TO postgres; + +-- +-- Name: TABLE lookup_unit_attrs_api; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lookup_unit_attrs_api IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: lookup_unit_intervals; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lookup_unit_intervals ( + unit_id integer, + fo_age numeric, + b_age numeric, + fo_interval character varying(50), + fo_period character varying(50), + lo_age numeric, + t_age numeric, + lo_interval character varying(50), + lo_period character varying(50), + age character varying(50), + age_id integer, + epoch character varying(50), + epoch_id integer, + period character varying(50), + period_id integer, + era character varying(50), + era_id integer, + eon character varying(50), + eon_id integer, + best_interval_id integer +); + + +ALTER TABLE macrostrat.lookup_unit_intervals OWNER TO postgres; + +-- +-- Name: TABLE lookup_unit_intervals; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lookup_unit_intervals IS 'Last updated from MariaDB - 2021-08-30 11:26'; + + +-- +-- Name: lookup_unit_liths; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lookup_unit_liths ( + unit_id integer, + lith_class character varying(100), + lith_type character varying(100), + lith_short text, + lith_long text, + environ_class character varying(100), + environ_type character varying(100), + environ character varying(255) +); + + +ALTER TABLE macrostrat.lookup_unit_liths OWNER TO postgres; + +-- +-- Name: TABLE lookup_unit_liths; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lookup_unit_liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: lookup_units; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.lookup_units ( + unit_id integer NOT NULL, + col_area numeric NOT NULL, + project_id integer NOT NULL, + t_int integer, + t_int_name text, + t_int_age numeric, + t_age numeric, + t_prop numeric, + t_plat numeric, + t_plng numeric, + b_int integer, + b_int_name text, + b_int_age numeric, + b_age numeric, + b_prop numeric, + b_plat numeric, + b_plng numeric, + clat numeric, + clng numeric, + color text, + text_color text, + units_above text, + units_below text, + pbdb_collections integer, + pbdb_occurrences integer, + age text, + age_id integer, + epoch text, + epoch_id integer, + period text, + period_id integer, + era text, + era_id integer, + eon text, + eon_id integer +); + + +ALTER TABLE macrostrat.lookup_units OWNER TO postgres; + +-- +-- Name: TABLE lookup_units; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.lookup_units IS 'Last updated from MariaDB - 2021-08-30 11:29'; + + +-- +-- Name: lookup_units_unit_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.lookup_units_unit_id_seq + START WITH 52383 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.lookup_units_unit_id_seq OWNER TO postgres; + +-- +-- Name: lookup_units_unit_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.lookup_units_unit_id_seq OWNED BY macrostrat.lookup_units.unit_id; + + +-- +-- Name: measurements; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.measurements ( + id integer NOT NULL, + measurement_class public.measurement_class NOT NULL, + measurement_type public.measurement_type NOT NULL, + measurement text NOT NULL +); + + +ALTER TABLE macrostrat.measurements OWNER TO postgres; + +-- +-- Name: TABLE measurements; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.measurements IS 'Last updated from MariaDB - 2022-02-25 15:08'; + + +-- +-- Name: measurements_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measurements_id_seq + START WITH 125 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measurements_id_seq OWNER TO postgres; + +-- +-- Name: measurements_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measurements_id_seq OWNED BY macrostrat.measurements.id; + + +-- +-- Name: measurements_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measurements_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measurements_new_id_seq OWNER TO postgres; + +-- +-- Name: measurements_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measurements_new_id_seq1 + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measurements_new_id_seq1 OWNER TO postgres; + +-- +-- Name: measurements_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measurements_new_id_seq1 OWNED BY macrostrat.measurements.id; + + +-- +-- Name: measuremeta; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.measuremeta ( + id integer NOT NULL, + sample_name text NOT NULL, + lat numeric(8,5), + lng numeric(8,5), + sample_geo_unit text NOT NULL, + sample_lith text, + lith_id integer NOT NULL, + lith_att_id bigint NOT NULL, + age text NOT NULL, + early_id bigint NOT NULL, + late_id bigint NOT NULL, + sample_descrip text, + ref text NOT NULL, + ref_id bigint NOT NULL +); + + +ALTER TABLE macrostrat.measuremeta OWNER TO postgres; + +-- +-- Name: TABLE measuremeta; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.measuremeta IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: measuremeta_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measuremeta_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measuremeta_id_seq OWNER TO postgres; + +-- +-- Name: measuremeta_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measuremeta_id_seq OWNED BY macrostrat.measuremeta.id; + + +-- +-- Name: measuremeta_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measuremeta_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measuremeta_new_id_seq OWNER TO postgres; + +-- +-- Name: measuremeta_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measuremeta_new_id_seq OWNED BY macrostrat.measuremeta.id; + + +-- +-- Name: measures; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.measures ( + id integer NOT NULL, + measuremeta_id integer NOT NULL, + measurement_id integer NOT NULL, + sample_no character varying(50), + measure_phase character varying(100) NOT NULL, + method character varying(100) NOT NULL, + units character varying(25) NOT NULL, + measure_value numeric(10,5), + v_error numeric(10,5), + v_error_units character varying(25), + v_type character varying(100), + v_n integer +); + + +ALTER TABLE macrostrat.measures OWNER TO postgres; + +-- +-- Name: TABLE measures; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.measures IS 'Last updated from MariaDB - 2021-08-30 11:58'; + + +-- +-- Name: measures_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.measures_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.measures_new_id_seq OWNER TO postgres; + +-- +-- Name: measures_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.measures_new_id_seq OWNED BY macrostrat.measures.id; + + +-- +-- Name: pbdb_collections; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.pbdb_collections ( + collection_no integer NOT NULL, + name text, + early_age numeric, + late_age numeric, + grp text, + grp_clean text, + formation text, + formation_clean text, + member text, + member_clean text, + lithologies text[], + environment text, + reference_no integer, + n_occs integer, + geom public.geometry(Geometry,4326) +); + + +ALTER TABLE macrostrat.pbdb_collections OWNER TO postgres; + +-- +-- Name: TABLE pbdb_collections; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.pbdb_collections IS 'Last updated from MariaDB - 2021-08-30 12:01'; + + +-- +-- Name: pbdb_collections_strat_names; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.pbdb_collections_strat_names ( + collection_no integer NOT NULL, + strat_name_id integer NOT NULL, + basis_col text +); + + +ALTER TABLE macrostrat.pbdb_collections_strat_names OWNER TO postgres; + +-- +-- Name: places; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.places ( + place_id integer NOT NULL, + name text, + abbrev text, + postal text, + country text, + country_abbrev text, + geom public.geometry +); + + +ALTER TABLE macrostrat.places OWNER TO postgres; + +-- +-- Name: TABLE places; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.places IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: places_place_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.places_place_id_seq + START WITH 88 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.places_place_id_seq OWNER TO postgres; + +-- +-- Name: places_place_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.places_place_id_seq OWNED BY macrostrat.places.place_id; + + +-- +-- Name: projects; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.projects ( + id integer NOT NULL, + project text, + descrip text, + timescale_id integer +); + + +ALTER TABLE macrostrat.projects OWNER TO postgres; + +-- +-- Name: TABLE projects; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.projects IS 'Last updated from MariaDB - 2022-02-25 14:40'; + + +-- +-- Name: projects_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.projects_id_seq + START WITH 13 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.projects_id_seq OWNER TO postgres; + +-- +-- Name: projects_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.projects_id_seq OWNED BY macrostrat.projects.id; + + +-- +-- Name: projects_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.projects_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.projects_new_id_seq OWNER TO postgres; + +-- +-- Name: projects_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.projects_new_id_seq OWNED BY macrostrat.projects.id; + + +-- +-- Name: refs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.refs ( + id integer NOT NULL, + pub_year integer, + author character varying(255), + ref text, + doi character varying(40), + compilation_code character varying(100), + url text, + rgeom public.geometry(Geometry,4326) +); + + +ALTER TABLE macrostrat.refs OWNER TO postgres; + +-- +-- Name: TABLE refs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.refs IS 'Last updated from MariaDB - 2021-08-30 11:25'; + + +-- +-- Name: refs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.refs_id_seq + START WITH 218 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.refs_id_seq OWNER TO postgres; + +-- +-- Name: refs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.refs_id_seq OWNED BY macrostrat.refs.id; + + +-- +-- Name: sections; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.sections ( + id integer NOT NULL, + col_id integer +); + + +ALTER TABLE macrostrat.sections OWNER TO postgres; + +-- +-- Name: TABLE sections; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.sections IS 'Last updated from MariaDB - 2022-02-25 14:41'; + + +-- +-- Name: sections_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.sections_id_seq + START WITH 12737 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.sections_id_seq OWNER TO postgres; + +-- +-- Name: sections_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.sections_id_seq OWNED BY macrostrat.sections.id; + + +-- +-- Name: sections_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.sections_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.sections_new_id_seq OWNER TO postgres; + +-- +-- Name: sections_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.sections_new_id_seq OWNED BY macrostrat.sections.id; + + +-- +-- Name: strat_name_footprints; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_name_footprints ( + strat_name_id integer, + name_no_lith character varying(100), + rank_name character varying(200), + concept_id integer, + concept_names integer[], + geom public.geometry(Geometry,4326), + best_t_age numeric, + best_b_age numeric +); + + +ALTER TABLE macrostrat.strat_name_footprints OWNER TO postgres; + +-- +-- Name: strat_names; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_names ( + id integer NOT NULL, + strat_name character varying(100) NOT NULL, + rank character varying(50), + ref_id integer NOT NULL, + concept_id integer +); + + +ALTER TABLE macrostrat.strat_names OWNER TO postgres; + +-- +-- Name: TABLE strat_names; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.strat_names IS 'Last updated from MariaDB - 2021-08-30 11:31'; + + +-- +-- Name: strat_names_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_names_id_seq + START WITH 108117 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_names_id_seq OWNER TO postgres; + +-- +-- Name: strat_names_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_names_id_seq OWNED BY macrostrat.strat_names.id; + + +-- +-- Name: strat_names_meta; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_names_meta ( + concept_id integer NOT NULL, + orig_id integer NOT NULL, + name character varying(40), + geologic_age text, + interval_id integer NOT NULL, + b_int integer NOT NULL, + t_int integer NOT NULL, + usage_notes text, + other text, + province text, + url character varying(150), + ref_id integer NOT NULL +); + + +ALTER TABLE macrostrat.strat_names_meta OWNER TO postgres; + +-- +-- Name: TABLE strat_names_meta; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.strat_names_meta IS 'Last updated from MariaDB - 2021-08-30 11:28'; + + +-- +-- Name: strat_names_meta_concept_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_names_meta_concept_id_seq + START WITH 43927 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_names_meta_concept_id_seq OWNER TO postgres; + +-- +-- Name: strat_names_meta_concept_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_names_meta_concept_id_seq OWNED BY macrostrat.strat_names_meta.concept_id; + + +-- +-- Name: strat_names_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_names_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_names_new_id_seq OWNER TO postgres; + +-- +-- Name: strat_names_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_names_new_id_seq OWNED BY macrostrat.strat_names.id; + + +-- +-- Name: strat_names_places; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_names_places ( + strat_name_id integer NOT NULL, + place_id integer NOT NULL +); + + +ALTER TABLE macrostrat.strat_names_places OWNER TO postgres; + +-- +-- Name: TABLE strat_names_places; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.strat_names_places IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: strat_tree; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.strat_tree ( + id integer NOT NULL, + parent integer, + child integer, + ref_id integer +); + + +ALTER TABLE macrostrat.strat_tree OWNER TO postgres; + +-- +-- Name: TABLE strat_tree; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.strat_tree IS 'Last updated from MariaDB - 2022-02-25 14:40'; + + +-- +-- Name: strat_tree_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_tree_id_seq + START WITH 29785 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_tree_id_seq OWNER TO postgres; + +-- +-- Name: strat_tree_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_tree_id_seq OWNED BY macrostrat.strat_tree.id; + + +-- +-- Name: strat_tree_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.strat_tree_new_id_seq1 + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.strat_tree_new_id_seq1 OWNER TO postgres; + +-- +-- Name: strat_tree_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.strat_tree_new_id_seq1 OWNED BY macrostrat.strat_tree.id; + + +-- +-- Name: timescales; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.timescales ( + id integer NOT NULL, + timescale character varying(100), + ref_id integer +); + + +ALTER TABLE macrostrat.timescales OWNER TO postgres; + +-- +-- Name: TABLE timescales; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.timescales IS 'Last updated from MariaDB - 2021-08-30 11:29'; + + +-- +-- Name: timescales_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.timescales_id_seq + START WITH 29 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.timescales_id_seq OWNER TO postgres; + +-- +-- Name: timescales_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.timescales_id_seq OWNED BY macrostrat.timescales.id; + + +-- +-- Name: timescales_intervals; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.timescales_intervals ( + timescale_id integer, + interval_id integer +); + + +ALTER TABLE macrostrat.timescales_intervals OWNER TO postgres; + +-- +-- Name: TABLE timescales_intervals; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.timescales_intervals IS 'Last updated from MariaDB - 2022-02-25 14:29'; + + +-- +-- Name: unit_econs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_econs ( + id integer NOT NULL, + unit_id integer, + econ_id integer, + ref_id integer, + date_mod text +); + + +ALTER TABLE macrostrat.unit_econs OWNER TO postgres; + +-- +-- Name: TABLE unit_econs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_econs IS 'Last updated from MariaDB - 2021-08-30 11:25'; + + +-- +-- Name: unit_econs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_econs_id_seq + START WITH 3158 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_econs_id_seq OWNER TO postgres; + +-- +-- Name: unit_econs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_econs_id_seq OWNED BY macrostrat.unit_econs.id; + + +-- +-- Name: unit_environs; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_environs ( + id integer NOT NULL, + unit_id integer, + environ_id integer, + ref_id integer, + date_mod text +); + + +ALTER TABLE macrostrat.unit_environs OWNER TO postgres; + +-- +-- Name: TABLE unit_environs; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_environs IS 'Last updated from MariaDB - 2021-08-30 11:25'; + + +-- +-- Name: unit_environs_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_environs_id_seq + START WITH 85924 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_environs_id_seq OWNER TO postgres; + +-- +-- Name: unit_environs_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_environs_id_seq OWNED BY macrostrat.unit_environs.id; + + +-- +-- Name: unit_lith_atts; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_lith_atts ( + id integer NOT NULL, + unit_lith_id integer, + lith_att_id integer, + ref_id integer, + date_mod text +); + + +ALTER TABLE macrostrat.unit_lith_atts OWNER TO postgres; + +-- +-- Name: TABLE unit_lith_atts; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_lith_atts IS 'Last updated from MariaDB - 2021-08-30 11:25'; + + +-- +-- Name: unit_lith_atts_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_lith_atts_id_seq + START WITH 60953 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_lith_atts_id_seq OWNER TO postgres; + +-- +-- Name: unit_lith_atts_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_lith_atts_id_seq OWNED BY macrostrat.unit_lith_atts.id; + + +-- +-- Name: unit_liths; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_liths ( + id integer NOT NULL, + lith_id integer, + unit_id integer, + prop text, + dom text, + comp_prop numeric, + mod_prop numeric, + toc numeric, + ref_id integer, + date_mod text +); + + +ALTER TABLE macrostrat.unit_liths OWNER TO postgres; + +-- +-- Name: TABLE unit_liths; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_liths IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: unit_liths_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_liths_id_seq + START WITH 132637 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_liths_id_seq OWNER TO postgres; + +-- +-- Name: unit_liths_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_liths_id_seq OWNED BY macrostrat.unit_liths.id; + + +-- +-- Name: unit_measures; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_measures ( + id integer NOT NULL, + measuremeta_id integer NOT NULL, + unit_id integer NOT NULL, + strat_name_id integer NOT NULL, + match_basis character varying(10) NOT NULL, + rel_position numeric(6,5) +); + + +ALTER TABLE macrostrat.unit_measures OWNER TO postgres; + +-- +-- Name: TABLE unit_measures; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_measures IS 'Last updated from MariaDB - 2018-09-25 10:40'; + + +-- +-- Name: unit_measures_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_measures_id_seq + START WITH 105049 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_measures_id_seq OWNER TO postgres; + +-- +-- Name: unit_measures_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_measures_id_seq OWNED BY macrostrat.unit_measures.id; + + +-- +-- Name: unit_measures_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_measures_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_measures_new_id_seq OWNER TO postgres; + +-- +-- Name: unit_measures_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_measures_new_id_seq OWNED BY macrostrat.unit_measures.id; + + +-- +-- Name: unit_strat_names; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.unit_strat_names ( + id integer NOT NULL, + unit_id integer NOT NULL, + strat_name_id integer NOT NULL +); + + +ALTER TABLE macrostrat.unit_strat_names OWNER TO postgres; + +-- +-- Name: TABLE unit_strat_names; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.unit_strat_names IS 'Last updated from MariaDB - 2022-02-25 14:28'; + + +-- +-- Name: unit_strat_names_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_strat_names_id_seq + START WITH 32147 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_strat_names_id_seq OWNER TO postgres; + +-- +-- Name: unit_strat_names_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_strat_names_id_seq OWNED BY macrostrat.unit_strat_names.id; + + +-- +-- Name: unit_strat_names_new_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.unit_strat_names_new_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.unit_strat_names_new_id_seq OWNER TO postgres; + +-- +-- Name: unit_strat_names_new_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.unit_strat_names_new_id_seq OWNED BY macrostrat.unit_strat_names.id; + + +-- +-- Name: units; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.units ( + id integer NOT NULL, + strat_name character varying(150), + color character varying(20), + outcrop character varying(20), + fo integer, + lo integer, + position_bottom numeric, + position_top numeric, + max_thick numeric, + min_thick numeric, + section_id integer, + col_id integer, + notes text, + strat_name_id integer +); + + +ALTER TABLE macrostrat.units OWNER TO postgres; + +-- +-- Name: TABLE units; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.units IS 'Last updated from MariaDB - 2022-02-25 14:47'; + + +-- +-- Name: units_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.units_id_seq + START WITH 53232 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.units_id_seq OWNER TO postgres; + +-- +-- Name: units_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.units_id_seq OWNED BY macrostrat.units.id; + + +-- +-- Name: units_sections; Type: TABLE; Schema: macrostrat; Owner: postgres +-- + +CREATE TABLE macrostrat.units_sections ( + id integer NOT NULL, + unit_id integer NOT NULL, + section_id integer NOT NULL, + col_id integer NOT NULL +); + + +ALTER TABLE macrostrat.units_sections OWNER TO postgres; + +-- +-- Name: TABLE units_sections; Type: COMMENT; Schema: macrostrat; Owner: postgres +-- + +COMMENT ON TABLE macrostrat.units_sections IS 'Last updated from MariaDB - 2021-08-30 11:59'; + + +-- +-- Name: units_sections_id_seq; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.units_sections_id_seq + START WITH 50897 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.units_sections_id_seq OWNER TO postgres; + +-- +-- Name: units_sections_id_seq; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.units_sections_id_seq OWNED BY macrostrat.units_sections.id; + + +-- +-- Name: units_sections_new_id_seq1; Type: SEQUENCE; Schema: macrostrat; Owner: postgres +-- + +CREATE SEQUENCE macrostrat.units_sections_new_id_seq1 + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE macrostrat.units_sections_new_id_seq1 OWNER TO postgres; + +-- +-- Name: units_sections_new_id_seq1; Type: SEQUENCE OWNED BY; Schema: macrostrat; Owner: postgres +-- + +ALTER SEQUENCE macrostrat.units_sections_new_id_seq1 OWNED BY macrostrat.units_sections.id; + + +-- +-- Name: col_form; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.col_form AS + SELECT c.id AS col_id, + c.col_name, + c.col AS col_number, + c.notes, + json_build_object('id', r.id, 'pub_year', r.pub_year, 'author', r.author, 'ref', r.ref, 'doi', r.doi, 'url', r.url) AS ref + FROM ((macrostrat.cols c + LEFT JOIN macrostrat.col_refs cr ON ((c.id = cr.col_id))) + LEFT JOIN macrostrat.refs r ON ((cr.ref_id = r.id))); + + +ALTER TABLE macrostrat_api.col_form OWNER TO api_user; + +-- +-- Name: col_group_view; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.col_group_view AS +SELECT + NULL::integer AS id, + NULL::character varying(100) AS col_group, + NULL::character varying(100) AS col_group_long, + NULL::integer AS project_id, + NULL::json AS cols; + + +ALTER TABLE macrostrat_api.col_group_view OWNER TO api_user; + +-- +-- Name: col_groups; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.col_groups AS + SELECT col_groups.id, + col_groups.col_group, + col_groups.col_group_long, + col_groups.project_id + FROM macrostrat.col_groups; + + +ALTER TABLE macrostrat_api.col_groups OWNER TO api_user; + +-- +-- Name: col_refs; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.col_refs AS + SELECT col_refs.id, + col_refs.col_id, + col_refs.ref_id + FROM macrostrat.col_refs; + + +ALTER TABLE macrostrat_api.col_refs OWNER TO api_user; + +-- +-- Name: col_sections; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.col_sections AS + SELECT c.id AS col_id, + c.col_name, + u.section_id, + u.position_top, + u.position_bottom, + fo.interval_name AS bottom, + lo.interval_name AS top + FROM (((macrostrat.cols c + LEFT JOIN macrostrat.units u ON ((u.col_id = c.id))) + LEFT JOIN macrostrat.intervals fo ON ((u.fo = fo.id))) + LEFT JOIN macrostrat.intervals lo ON ((u.lo = lo.id))); + + +ALTER TABLE macrostrat_api.col_sections OWNER TO api_user; + +-- +-- Name: cols; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.cols AS + SELECT cols.id, + cols.col_group_id, + cols.project_id, + cols.col_type, + cols.status_code, + cols.col_position, + cols.col, + cols.col_name, + cols.lat, + cols.lng, + cols.col_area, + cols.coordinate, + cols.wkt, + cols.created, + cols.poly_geom, + cols.notes + FROM macrostrat.cols; + + +ALTER TABLE macrostrat_api.cols OWNER TO api_user; + +-- +-- Name: data_roles; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.data_roles AS + SELECT data_roles.id, + data_roles.role, + data_roles.description + FROM auth.data_roles; + + +ALTER TABLE macrostrat_api.data_roles OWNER TO api_user; + +-- +-- Name: econ_unit; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.econ_unit AS + SELECT e.id, + e.econ, + e.econ_type, + e.econ_class, + e.econ_color, + ue.unit_id, + ue.ref_id + FROM (macrostrat.econs e + JOIN macrostrat.unit_econs ue ON ((e.id = ue.econ_id))); + + +ALTER TABLE macrostrat_api.econ_unit OWNER TO api_user; + +-- +-- Name: environ_unit; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.environ_unit AS + SELECT e.id, + e.environ, + e.environ_type, + e.environ_class, + e.environ_color, + ue.unit_id, + ue.ref_id + FROM (macrostrat.environs e + JOIN macrostrat.unit_environs ue ON ((e.id = ue.environ_id))); + + +ALTER TABLE macrostrat_api.environ_unit OWNER TO api_user; + +-- +-- Name: environs; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.environs AS + SELECT environs.id, + environs.environ, + environs.environ_type, + environs.environ_class, + environs.environ_color + FROM macrostrat.environs; + + +ALTER TABLE macrostrat_api.environs OWNER TO api_user; + +-- +-- Name: intervals; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.intervals AS + SELECT intervals.id, + intervals.age_bottom, + intervals.age_top, + intervals.interval_name, + intervals.interval_abbrev, + intervals.interval_type, + intervals.interval_color, + intervals.rank + FROM macrostrat.intervals; + + +ALTER TABLE macrostrat_api.intervals OWNER TO api_user; + +-- +-- Name: lith_attr_unit; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.lith_attr_unit AS + SELECT la.id AS lith_attr_id, + la.lith_att, + la.att_type, + la.lith_att_fill, + l.id, + l.lith, + l.lith_group, + l.lith_type, + l.lith_class, + l.lith_equiv, + l.lith_fill, + l.comp_coef, + l.initial_porosity, + l.bulk_density, + l.lith_color, + ul.unit_id + FROM (((macrostrat.lith_atts la + JOIN macrostrat.unit_lith_atts ula ON ((ula.lith_att_id = la.id))) + JOIN macrostrat.unit_liths ul ON ((ul.id = ula.unit_lith_id))) + JOIN macrostrat.liths l ON ((ul.lith_id = l.id))); + + +ALTER TABLE macrostrat_api.lith_attr_unit OWNER TO api_user; + +-- +-- Name: lith_unit; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.lith_unit AS + SELECT l.id, + l.lith, + l.lith_group, + l.lith_type, + l.lith_class, + l.lith_color, + ul.prop, + ul.mod_prop, + ul.comp_prop, + ul.ref_id, + ul.unit_id + FROM (macrostrat.unit_liths ul + JOIN macrostrat.liths l ON ((ul.lith_id = l.id))); + + +ALTER TABLE macrostrat_api.lith_unit OWNER TO api_user; + +-- +-- Name: liths; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.liths AS + SELECT liths.id, + liths.lith, + liths.lith_group, + liths.lith_type, + liths.lith_class, + liths.lith_equiv, + liths.lith_fill, + liths.comp_coef, + liths.initial_porosity, + liths.bulk_density, + liths.lith_color + FROM macrostrat.liths; + + +ALTER TABLE macrostrat_api.liths OWNER TO api_user; + +-- +-- Name: projects; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.projects AS + SELECT projects.id, + projects.project, + projects.descrip, + projects.timescale_id + FROM macrostrat.projects; + + +ALTER TABLE macrostrat_api.projects OWNER TO api_user; + +-- +-- Name: refs; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.refs AS + SELECT refs.id, + refs.pub_year, + refs.author, + refs.ref, + refs.doi, + refs.compilation_code, + refs.url, + refs.rgeom + FROM macrostrat.refs; + + +ALTER TABLE macrostrat_api.refs OWNER TO api_user; + +-- +-- Name: sections; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.sections AS + SELECT sections.id, + sections.col_id + FROM macrostrat.sections; + + +ALTER TABLE macrostrat_api.sections OWNER TO api_user; + +-- +-- Name: strat_names; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.strat_names AS + SELECT s.id, + s.strat_name, + s.rank, + row_to_json(r.*) AS ref, + row_to_json(sm.*) AS concept + FROM ((macrostrat.strat_names s + LEFT JOIN macrostrat.refs r ON ((r.id = s.ref_id))) + LEFT JOIN macrostrat.strat_names_meta sm ON ((sm.concept_id = s.concept_id))); + + +ALTER TABLE macrostrat_api.strat_names OWNER TO api_user; + +-- +-- Name: strat_tree; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.strat_tree AS + SELECT strat_tree.id, + strat_tree.parent, + strat_tree.child, + strat_tree.ref_id + FROM macrostrat.strat_tree; + + +ALTER TABLE macrostrat_api.strat_tree OWNER TO api_user; + +-- +-- Name: timescales; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.timescales AS + SELECT timescales.id, + timescales.timescale, + timescales.ref_id + FROM macrostrat.timescales; + + +ALTER TABLE macrostrat_api.timescales OWNER TO api_user; + +-- +-- Name: unit_environs; Type: VIEW; Schema: macrostrat_api; Owner: postgres +-- + +CREATE VIEW macrostrat_api.unit_environs AS + SELECT unit_environs.id, + unit_environs.unit_id, + unit_environs.environ_id, + unit_environs.ref_id, + unit_environs.date_mod + FROM macrostrat.unit_environs; + + +ALTER TABLE macrostrat_api.unit_environs OWNER TO postgres; + +-- +-- Name: unit_liths; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.unit_liths AS + SELECT unit_liths.id, + unit_liths.lith_id, + unit_liths.unit_id, + unit_liths.prop, + unit_liths.dom, + unit_liths.comp_prop, + unit_liths.mod_prop, + unit_liths.toc, + unit_liths.ref_id, + unit_liths.date_mod + FROM macrostrat.unit_liths; + + +ALTER TABLE macrostrat_api.unit_liths OWNER TO api_user; + +-- +-- Name: units; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.units AS + SELECT units.id, + units.strat_name, + units.color, + units.outcrop, + units.fo, + units.lo, + units.position_bottom, + units.position_top, + units.max_thick, + units.min_thick, + units.section_id, + units.col_id, + units.notes, + units.strat_name_id + FROM macrostrat.units; + + +ALTER TABLE macrostrat_api.units OWNER TO api_user; + +-- +-- Name: units_view; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.units_view AS + SELECT u.id, + u.strat_name AS unit_strat_name, + to_jsonb(s.*) AS strat_name, + u.color, + u.outcrop, + u.fo, + u.lo, + u.position_bottom, + u.position_top, + u.max_thick, + u.min_thick, + u.section_id, + u.col_id, + u.notes, + fo.interval_name AS name_fo, + fo.age_bottom, + lo.interval_name AS name_lo, + lo.age_top + FROM (((macrostrat.units u + LEFT JOIN macrostrat.intervals fo ON ((u.fo = fo.id))) + LEFT JOIN macrostrat.intervals lo ON ((u.lo = lo.id))) + LEFT JOIN macrostrat.strat_names s ON ((u.strat_name_id = s.id))); + + +ALTER TABLE macrostrat_api.units_view OWNER TO api_user; + +-- +-- Name: user_projects; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.user_projects AS + SELECT user_projects.id, + user_projects.user_, + user_projects.project, + user_projects.role_id + FROM auth.user_projects; + + +ALTER TABLE macrostrat_api.user_projects OWNER TO api_user; + +-- +-- Name: users; Type: VIEW; Schema: macrostrat_api; Owner: api_user +-- + +CREATE VIEW macrostrat_api.users AS + SELECT users.id, + users.firstname, + users.lastname, + users.username, + users.pass, + users.role + FROM auth.users; + + +ALTER TABLE macrostrat_api.users OWNER TO api_user; + +-- +-- Name: data_roles id; Type: DEFAULT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.data_roles ALTER COLUMN id SET DEFAULT nextval('auth.data_roles_id_seq'::regclass); + + +-- +-- Name: user_projects id; Type: DEFAULT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.user_projects ALTER COLUMN id SET DEFAULT nextval('auth.user_projects_id_seq'::regclass); + + +-- +-- Name: users id; Type: DEFAULT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.users ALTER COLUMN id SET DEFAULT nextval('auth.users_id_seq'::regclass); + + +-- +-- Name: col_areas id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_areas ALTER COLUMN id SET DEFAULT nextval('macrostrat.col_areas_id_seq'::regclass); + + +-- +-- Name: col_groups id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_groups ALTER COLUMN id SET DEFAULT nextval('macrostrat.col_groups_id_seq'::regclass); + + +-- +-- Name: col_refs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs ALTER COLUMN id SET DEFAULT nextval('macrostrat.col_refs_id_seq'::regclass); + + +-- +-- Name: cols id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols ALTER COLUMN id SET DEFAULT nextval('macrostrat.cols_id_seq'::regclass); + + +-- +-- Name: econs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.econs ALTER COLUMN id SET DEFAULT nextval('macrostrat.econs_id_seq'::regclass); + + +-- +-- Name: environs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.environs ALTER COLUMN id SET DEFAULT nextval('macrostrat.environs_id_seq'::regclass); + + +-- +-- Name: grainsize grain_id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.grainsize ALTER COLUMN grain_id SET DEFAULT nextval('macrostrat.grainsize_grain_id_seq'::regclass); + + +-- +-- Name: intervals id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.intervals ALTER COLUMN id SET DEFAULT nextval('macrostrat.intervals_id_seq'::regclass); + + +-- +-- Name: lith_atts id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.lith_atts ALTER COLUMN id SET DEFAULT nextval('macrostrat.lith_atts_id_seq'::regclass); + + +-- +-- Name: liths id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.liths ALTER COLUMN id SET DEFAULT nextval('macrostrat.liths_id_seq'::regclass); + + +-- +-- Name: lookup_units unit_id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.lookup_units ALTER COLUMN unit_id SET DEFAULT nextval('macrostrat.lookup_units_unit_id_seq'::regclass); + + +-- +-- Name: measurements id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measurements ALTER COLUMN id SET DEFAULT nextval('macrostrat.measurements_id_seq'::regclass); + + +-- +-- Name: measuremeta id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measuremeta ALTER COLUMN id SET DEFAULT nextval('macrostrat.measuremeta_id_seq'::regclass); + + +-- +-- Name: measures id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measures ALTER COLUMN id SET DEFAULT nextval('macrostrat.measures_new_id_seq'::regclass); + + +-- +-- Name: places place_id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.places ALTER COLUMN place_id SET DEFAULT nextval('macrostrat.places_place_id_seq'::regclass); + + +-- +-- Name: projects id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.projects ALTER COLUMN id SET DEFAULT nextval('macrostrat.projects_id_seq'::regclass); + + +-- +-- Name: refs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.refs ALTER COLUMN id SET DEFAULT nextval('macrostrat.refs_id_seq'::regclass); + + +-- +-- Name: sections id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections ALTER COLUMN id SET DEFAULT nextval('macrostrat.sections_id_seq'::regclass); + + +-- +-- Name: strat_names id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names ALTER COLUMN id SET DEFAULT nextval('macrostrat.strat_names_id_seq'::regclass); + + +-- +-- Name: strat_names_meta concept_id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_meta ALTER COLUMN concept_id SET DEFAULT nextval('macrostrat.strat_names_meta_concept_id_seq'::regclass); + + +-- +-- Name: strat_tree id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree ALTER COLUMN id SET DEFAULT nextval('macrostrat.strat_tree_id_seq'::regclass); + + +-- +-- Name: timescales id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales ALTER COLUMN id SET DEFAULT nextval('macrostrat.timescales_id_seq'::regclass); + + +-- +-- Name: unit_econs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_econs_id_seq'::regclass); + + +-- +-- Name: unit_environs id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_environs_id_seq'::regclass); + + +-- +-- Name: unit_lith_atts id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_lith_atts_id_seq'::regclass); + + +-- +-- Name: unit_liths id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_liths_id_seq'::regclass); + + +-- +-- Name: unit_measures id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_measures ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_measures_id_seq'::regclass); + + +-- +-- Name: unit_strat_names id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names ALTER COLUMN id SET DEFAULT nextval('macrostrat.unit_strat_names_id_seq'::regclass); + + +-- +-- Name: units id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units ALTER COLUMN id SET DEFAULT nextval('macrostrat.units_id_seq'::regclass); + + +-- +-- Name: units_sections id; Type: DEFAULT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units_sections ALTER COLUMN id SET DEFAULT nextval('macrostrat.units_sections_id_seq'::regclass); + + +-- +-- Name: data_roles data_roles_pkey; Type: CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.data_roles + ADD CONSTRAINT data_roles_pkey PRIMARY KEY (id); + + +-- +-- Name: user_projects user_projects_pkey; Type: CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.user_projects + ADD CONSTRAINT user_projects_pkey PRIMARY KEY (id); + + +-- +-- Name: users users_pkey; Type: CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + + +-- +-- Name: col_areas col_areas_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_areas + ADD CONSTRAINT col_areas_new_pkey PRIMARY KEY (id); + + +-- +-- Name: col_groups col_groups_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_groups + ADD CONSTRAINT col_groups_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: col_refs col_refs_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_new_pkey PRIMARY KEY (id); + + +-- +-- Name: cols cols_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: econs econs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.econs + ADD CONSTRAINT econs_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: environs environs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.environs + ADD CONSTRAINT environs_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: grainsize grainsize_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.grainsize + ADD CONSTRAINT grainsize_pkey PRIMARY KEY (grain_id); + + +-- +-- Name: intervals intervals_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.intervals + ADD CONSTRAINT intervals_pkey PRIMARY KEY (id); + + +-- +-- Name: lith_atts lith_atts_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.lith_atts + ADD CONSTRAINT lith_atts_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: liths liths_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.liths + ADD CONSTRAINT liths_new_pkey PRIMARY KEY (id); + + +-- +-- Name: lookup_units lookup_units_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.lookup_units + ADD CONSTRAINT lookup_units_new_pkey1 PRIMARY KEY (unit_id); + + +-- +-- Name: measurements measurements_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measurements + ADD CONSTRAINT measurements_new_pkey PRIMARY KEY (id); + + +-- +-- Name: measuremeta measuremeta_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.measuremeta + ADD CONSTRAINT measuremeta_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: places places_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.places + ADD CONSTRAINT places_new_pkey PRIMARY KEY (place_id); + + +-- +-- Name: projects projects_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.projects + ADD CONSTRAINT projects_new_pkey PRIMARY KEY (id); + + +-- +-- Name: refs refs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.refs + ADD CONSTRAINT refs_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: sections sections_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_new_pkey PRIMARY KEY (id); + + +-- +-- Name: strat_names_meta strat_names_meta_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_meta + ADD CONSTRAINT strat_names_meta_new_pkey1 PRIMARY KEY (concept_id); + + +-- +-- Name: strat_names strat_names_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names + ADD CONSTRAINT strat_names_new_pkey PRIMARY KEY (id); + + +-- +-- Name: strat_tree strat_tree_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: timescales timescales_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales + ADD CONSTRAINT timescales_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: unit_econs unit_econs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: unit_environs unit_environs_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: unit_lith_atts unit_lith_atts_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: unit_liths unit_liths_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_new_pkey PRIMARY KEY (id); + + +-- +-- Name: unit_measures unit_measures_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_measures + ADD CONSTRAINT unit_measures_new_pkey PRIMARY KEY (id); + + +-- +-- Name: unit_strat_names unit_strat_names_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_new_pkey PRIMARY KEY (id); + + +-- +-- Name: units units_new_pkey; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_new_pkey PRIMARY KEY (id); + + +-- +-- Name: units_sections units_sections_new_pkey1; Type: CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units_sections + ADD CONSTRAINT units_sections_new_pkey1 PRIMARY KEY (id); + + +-- +-- Name: autocomplete_new_category_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX autocomplete_new_category_idx ON macrostrat.autocomplete USING btree (category); + + +-- +-- Name: autocomplete_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX autocomplete_new_id_idx ON macrostrat.autocomplete USING btree (id); + + +-- +-- Name: autocomplete_new_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX autocomplete_new_name_idx ON macrostrat.autocomplete USING btree (name); + + +-- +-- Name: autocomplete_new_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX autocomplete_new_type_idx ON macrostrat.autocomplete USING btree (type); + + +-- +-- Name: col_areas_new_col_area_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX col_areas_new_col_area_idx ON macrostrat.col_areas USING gist (col_area); + + +-- +-- Name: col_areas_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX col_areas_new_col_id_idx ON macrostrat.col_areas USING btree (col_id); + + +-- +-- Name: col_groups_new_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX col_groups_new_id_idx1 ON macrostrat.col_groups USING btree (id); + + +-- +-- Name: col_refs_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX col_refs_new_col_id_idx ON macrostrat.col_refs USING btree (col_id); + + +-- +-- Name: col_refs_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX col_refs_new_ref_id_idx ON macrostrat.col_refs USING btree (ref_id); + + +-- +-- Name: cols_new_col_group_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX cols_new_col_group_id_idx1 ON macrostrat.cols USING btree (col_group_id); + + +-- +-- Name: cols_new_coordinate_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX cols_new_coordinate_idx1 ON macrostrat.cols USING gist (coordinate); + + +-- +-- Name: cols_new_poly_geom_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX cols_new_poly_geom_idx1 ON macrostrat.cols USING gist (poly_geom); + + +-- +-- Name: cols_new_project_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX cols_new_project_id_idx1 ON macrostrat.cols USING btree (project_id); + + +-- +-- Name: cols_new_status_code_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX cols_new_status_code_idx1 ON macrostrat.cols USING btree (status_code); + + +-- +-- Name: concepts_places_new_concept_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX concepts_places_new_concept_id_idx ON macrostrat.concepts_places USING btree (concept_id); + + +-- +-- Name: concepts_places_new_place_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX concepts_places_new_place_id_idx ON macrostrat.concepts_places USING btree (place_id); + + +-- +-- Name: intervals_new_age_bottom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX intervals_new_age_bottom_idx ON macrostrat.intervals USING btree (age_bottom); + + +-- +-- Name: intervals_new_age_top_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX intervals_new_age_top_idx ON macrostrat.intervals USING btree (age_top); + + +-- +-- Name: intervals_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX intervals_new_id_idx ON macrostrat.intervals USING btree (id); + + +-- +-- Name: intervals_new_interval_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX intervals_new_interval_name_idx ON macrostrat.intervals USING btree (interval_name); + + +-- +-- Name: intervals_new_interval_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX intervals_new_interval_type_idx ON macrostrat.intervals USING btree (interval_type); + + +-- +-- Name: lith_atts_new_att_type_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lith_atts_new_att_type_idx1 ON macrostrat.lith_atts USING btree (att_type); + + +-- +-- Name: lith_atts_new_lith_att_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lith_atts_new_lith_att_idx1 ON macrostrat.lith_atts USING btree (lith_att); + + +-- +-- Name: liths_new_lith_class_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX liths_new_lith_class_idx ON macrostrat.liths USING btree (lith_class); + + +-- +-- Name: liths_new_lith_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX liths_new_lith_idx ON macrostrat.liths USING btree (lith); + + +-- +-- Name: liths_new_lith_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX liths_new_lith_type_idx ON macrostrat.liths USING btree (lith_type); + + +-- +-- Name: lookup_strat_names_new_bed_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_bed_id_idx1 ON macrostrat.lookup_strat_names USING btree (bed_id); + + +-- +-- Name: lookup_strat_names_new_concept_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_concept_id_idx1 ON macrostrat.lookup_strat_names USING btree (concept_id); + + +-- +-- Name: lookup_strat_names_new_fm_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_fm_id_idx1 ON macrostrat.lookup_strat_names USING btree (fm_id); + + +-- +-- Name: lookup_strat_names_new_gp_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_gp_id_idx1 ON macrostrat.lookup_strat_names USING btree (gp_id); + + +-- +-- Name: lookup_strat_names_new_mbr_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_mbr_id_idx1 ON macrostrat.lookup_strat_names USING btree (mbr_id); + + +-- +-- Name: lookup_strat_names_new_sgp_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_sgp_id_idx1 ON macrostrat.lookup_strat_names USING btree (sgp_id); + + +-- +-- Name: lookup_strat_names_new_strat_name_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_strat_name_id_idx1 ON macrostrat.lookup_strat_names USING btree (strat_name_id); + + +-- +-- Name: lookup_strat_names_new_strat_name_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_strat_names_new_strat_name_idx1 ON macrostrat.lookup_strat_names USING btree (strat_name); + + +-- +-- Name: lookup_unit_attrs_api_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_unit_attrs_api_new_unit_id_idx1 ON macrostrat.lookup_unit_attrs_api USING btree (unit_id); + + +-- +-- Name: lookup_unit_intervals_new_best_interval_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_unit_intervals_new_best_interval_id_idx ON macrostrat.lookup_unit_intervals USING btree (best_interval_id); + + +-- +-- Name: lookup_unit_intervals_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_unit_intervals_new_unit_id_idx ON macrostrat.lookup_unit_intervals USING btree (unit_id); + + +-- +-- Name: lookup_unit_liths_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_unit_liths_new_unit_id_idx ON macrostrat.lookup_unit_liths USING btree (unit_id); + + +-- +-- Name: lookup_units_new_b_int_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_units_new_b_int_idx1 ON macrostrat.lookup_units USING btree (b_int); + + +-- +-- Name: lookup_units_new_project_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_units_new_project_id_idx1 ON macrostrat.lookup_units USING btree (project_id); + + +-- +-- Name: lookup_units_new_t_int_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX lookup_units_new_t_int_idx1 ON macrostrat.lookup_units USING btree (t_int); + + +-- +-- Name: measurements_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_id_idx ON macrostrat.measurements USING btree (id); + + +-- +-- Name: measurements_new_measurement_class_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_measurement_class_idx ON macrostrat.measurements USING btree (measurement_class); + + +-- +-- Name: measurements_new_measurement_type_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measurements_new_measurement_type_idx ON macrostrat.measurements USING btree (measurement_type); + + +-- +-- Name: measuremeta_new_lith_att_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measuremeta_new_lith_att_id_idx ON macrostrat.measuremeta USING btree (lith_att_id); + + +-- +-- Name: measuremeta_new_lith_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measuremeta_new_lith_id_idx ON macrostrat.measuremeta USING btree (lith_id); + + +-- +-- Name: measuremeta_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measuremeta_new_ref_id_idx ON macrostrat.measuremeta USING btree (ref_id); + + +-- +-- Name: measures_new_measurement_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measures_new_measurement_id_idx ON macrostrat.measures USING btree (measurement_id); + + +-- +-- Name: measures_new_measuremeta_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX measures_new_measuremeta_id_idx ON macrostrat.measures USING btree (measuremeta_id); + + +-- +-- Name: pbdb_collections_new_collection_no_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX pbdb_collections_new_collection_no_idx ON macrostrat.pbdb_collections USING btree (collection_no); + + +-- +-- Name: pbdb_collections_new_early_age_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX pbdb_collections_new_early_age_idx ON macrostrat.pbdb_collections USING btree (early_age); + + +-- +-- Name: pbdb_collections_new_geom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX pbdb_collections_new_geom_idx ON macrostrat.pbdb_collections USING gist (geom); + + +-- +-- Name: pbdb_collections_new_late_age_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX pbdb_collections_new_late_age_idx ON macrostrat.pbdb_collections USING btree (late_age); + + +-- +-- Name: places_new_geom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX places_new_geom_idx ON macrostrat.places USING gist (geom); + + +-- +-- Name: projects_new_project_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX projects_new_project_idx ON macrostrat.projects USING btree (project); + + +-- +-- Name: projects_new_timescale_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX projects_new_timescale_id_idx ON macrostrat.projects USING btree (timescale_id); + + +-- +-- Name: refs_new_rgeom_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX refs_new_rgeom_idx1 ON macrostrat.refs USING gist (rgeom); + + +-- +-- Name: sections_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX sections_new_col_id_idx ON macrostrat.sections USING btree (col_id); + + +-- +-- Name: sections_new_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX sections_new_id_idx ON macrostrat.sections USING btree (id); + + +-- +-- Name: strat_name_footprints_new_geom_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_name_footprints_new_geom_idx ON macrostrat.strat_name_footprints USING gist (geom); + + +-- +-- Name: strat_name_footprints_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_name_footprints_new_strat_name_id_idx ON macrostrat.strat_name_footprints USING btree (strat_name_id); + + +-- +-- Name: strat_names_meta_new_b_int_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_meta_new_b_int_idx1 ON macrostrat.strat_names_meta USING btree (b_int); + + +-- +-- Name: strat_names_meta_new_interval_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_meta_new_interval_id_idx1 ON macrostrat.strat_names_meta USING btree (interval_id); + + +-- +-- Name: strat_names_meta_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_meta_new_ref_id_idx1 ON macrostrat.strat_names_meta USING btree (ref_id); + + +-- +-- Name: strat_names_meta_new_t_int_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_meta_new_t_int_idx1 ON macrostrat.strat_names_meta USING btree (t_int); + + +-- +-- Name: strat_names_new_concept_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_new_concept_id_idx ON macrostrat.strat_names USING btree (concept_id); + + +-- +-- Name: strat_names_new_rank_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_new_rank_idx ON macrostrat.strat_names USING btree (rank); + + +-- +-- Name: strat_names_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_new_ref_id_idx ON macrostrat.strat_names USING btree (ref_id); + + +-- +-- Name: strat_names_new_strat_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_new_strat_name_idx ON macrostrat.strat_names USING btree (strat_name); + + +-- +-- Name: strat_names_places_new_place_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_places_new_place_id_idx ON macrostrat.strat_names_places USING btree (place_id); + + +-- +-- Name: strat_names_places_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_names_places_new_strat_name_id_idx ON macrostrat.strat_names_places USING btree (strat_name_id); + + +-- +-- Name: strat_tree_new_child_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_tree_new_child_idx1 ON macrostrat.strat_tree USING btree (child); + + +-- +-- Name: strat_tree_new_parent_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_tree_new_parent_idx1 ON macrostrat.strat_tree USING btree (parent); + + +-- +-- Name: strat_tree_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX strat_tree_new_ref_id_idx1 ON macrostrat.strat_tree USING btree (ref_id); + + +-- +-- Name: timescales_intervals_new_interval_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_intervals_new_interval_id_idx ON macrostrat.timescales_intervals USING btree (interval_id); + + +-- +-- Name: timescales_intervals_new_timescale_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_intervals_new_timescale_id_idx ON macrostrat.timescales_intervals USING btree (timescale_id); + + +-- +-- Name: timescales_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_new_ref_id_idx1 ON macrostrat.timescales USING btree (ref_id); + + +-- +-- Name: timescales_new_timescale_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX timescales_new_timescale_idx1 ON macrostrat.timescales USING btree (timescale); + + +-- +-- Name: unit_econs_new_econ_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_econs_new_econ_id_idx1 ON macrostrat.unit_econs USING btree (econ_id); + + +-- +-- Name: unit_econs_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_econs_new_ref_id_idx1 ON macrostrat.unit_econs USING btree (ref_id); + + +-- +-- Name: unit_econs_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_econs_new_unit_id_idx1 ON macrostrat.unit_econs USING btree (unit_id); + + +-- +-- Name: unit_environs_new_environ_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_environs_new_environ_id_idx1 ON macrostrat.unit_environs USING btree (environ_id); + + +-- +-- Name: unit_environs_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_environs_new_ref_id_idx1 ON macrostrat.unit_environs USING btree (ref_id); + + +-- +-- Name: unit_environs_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_environs_new_unit_id_idx1 ON macrostrat.unit_environs USING btree (unit_id); + + +-- +-- Name: unit_lith_atts_new_lith_att_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_lith_atts_new_lith_att_id_idx1 ON macrostrat.unit_lith_atts USING btree (lith_att_id); + + +-- +-- Name: unit_lith_atts_new_ref_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_lith_atts_new_ref_id_idx1 ON macrostrat.unit_lith_atts USING btree (ref_id); + + +-- +-- Name: unit_lith_atts_new_unit_lith_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_lith_atts_new_unit_lith_id_idx1 ON macrostrat.unit_lith_atts USING btree (unit_lith_id); + + +-- +-- Name: unit_liths_new_lith_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_liths_new_lith_id_idx ON macrostrat.unit_liths USING btree (lith_id); + + +-- +-- Name: unit_liths_new_ref_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_liths_new_ref_id_idx ON macrostrat.unit_liths USING btree (ref_id); + + +-- +-- Name: unit_liths_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_liths_new_unit_id_idx ON macrostrat.unit_liths USING btree (unit_id); + + +-- +-- Name: unit_measures_new_measuremeta_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_measures_new_measuremeta_id_idx ON macrostrat.unit_measures USING btree (measuremeta_id); + + +-- +-- Name: unit_measures_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_measures_new_strat_name_id_idx ON macrostrat.unit_measures USING btree (strat_name_id); + + +-- +-- Name: unit_measures_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_measures_new_unit_id_idx ON macrostrat.unit_measures USING btree (unit_id); + + +-- +-- Name: unit_strat_names_new_strat_name_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_strat_names_new_strat_name_id_idx ON macrostrat.unit_strat_names USING btree (strat_name_id); + + +-- +-- Name: unit_strat_names_new_unit_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX unit_strat_names_new_unit_id_idx ON macrostrat.unit_strat_names USING btree (unit_id); + + +-- +-- Name: units_new_col_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_new_col_id_idx ON macrostrat.units USING btree (col_id); + + +-- +-- Name: units_new_color_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_new_color_idx ON macrostrat.units USING btree (color); + + +-- +-- Name: units_new_section_id_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_new_section_id_idx ON macrostrat.units USING btree (section_id); + + +-- +-- Name: units_new_strat_name_idx; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_new_strat_name_idx ON macrostrat.units USING btree (strat_name); + + +-- +-- Name: units_sections_new_col_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_sections_new_col_id_idx1 ON macrostrat.units_sections USING btree (col_id); + + +-- +-- Name: units_sections_new_section_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_sections_new_section_id_idx1 ON macrostrat.units_sections USING btree (section_id); + + +-- +-- Name: units_sections_new_unit_id_idx1; Type: INDEX; Schema: macrostrat; Owner: postgres +-- + +CREATE INDEX units_sections_new_unit_id_idx1 ON macrostrat.units_sections USING btree (unit_id); + + +-- +-- Name: col_group_view _RETURN; Type: RULE; Schema: macrostrat_api; Owner: api_user +-- + +CREATE OR REPLACE VIEW macrostrat_api.col_group_view AS + SELECT cg.id, + cg.col_group, + cg.col_group_long, + cg.project_id, + json_agg(json_build_object('col_id', c.id, 'status_code', c.status_code, 'col_number', c.col, 'col_name', c.col_name)) AS cols + FROM (macrostrat.col_groups cg + LEFT JOIN macrostrat.cols c ON ((c.col_group_id = cg.id))) + GROUP BY cg.id, c.project_id; + + +-- +-- Name: users encrypt_pass; Type: TRIGGER; Schema: auth; Owner: postgres +-- + +CREATE TRIGGER encrypt_pass BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE FUNCTION auth.encrypt_pass(); + + +-- +-- Name: users ensure_user_role_exists; Type: TRIGGER; Schema: auth; Owner: postgres +-- + +CREATE TRIGGER ensure_user_role_exists BEFORE INSERT OR UPDATE ON auth.users FOR EACH ROW EXECUTE FUNCTION auth.check_role_exists(); + + +-- +-- Name: projects user_projects; Type: TRIGGER; Schema: macrostrat; Owner: postgres +-- + +CREATE TRIGGER user_projects AFTER INSERT ON macrostrat.projects FOR EACH ROW EXECUTE FUNCTION auth.user_project_insert(); + + +-- +-- Name: user_projects user_projects_project_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.user_projects + ADD CONSTRAINT user_projects_project_fkey FOREIGN KEY (project) REFERENCES macrostrat.projects(id); + + +-- +-- Name: user_projects user_projects_role_id_fkey; Type: FK CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.user_projects + ADD CONSTRAINT user_projects_role_id_fkey FOREIGN KEY (role_id) REFERENCES auth.data_roles(id); + + +-- +-- Name: user_projects user_projects_user__fkey; Type: FK CONSTRAINT; Schema: auth; Owner: postgres +-- + +ALTER TABLE ONLY auth.user_projects + ADD CONSTRAINT user_projects_user__fkey FOREIGN KEY (user_) REFERENCES auth.users(id); + + +-- +-- Name: col_areas col_areas_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_areas + ADD CONSTRAINT col_areas_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: col_areas col_areas_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_areas + ADD CONSTRAINT col_areas_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: col_groups col_groups_project_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_groups + ADD CONSTRAINT col_groups_project_id_fkey FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id); + + +-- +-- Name: col_refs col_refs_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: col_refs col_refs_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: col_refs col_refs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: col_refs col_refs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.col_refs + ADD CONSTRAINT col_refs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: cols cols_col_group_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_col_group_id_fkey FOREIGN KEY (col_group_id) REFERENCES macrostrat.col_groups(id) ON DELETE CASCADE; + + +-- +-- Name: cols cols_col_group_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_col_group_id_fkey1 FOREIGN KEY (col_group_id) REFERENCES macrostrat.col_groups(id) ON DELETE CASCADE; + + +-- +-- Name: cols cols_project_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_project_id_fkey FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE; + + +-- +-- Name: cols cols_project_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.cols + ADD CONSTRAINT cols_project_id_fkey1 FOREIGN KEY (project_id) REFERENCES macrostrat.projects(id) ON DELETE CASCADE; + + +-- +-- Name: concepts_places concepts_places_place_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.concepts_places + ADD CONSTRAINT concepts_places_place_id_fkey FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + +-- +-- Name: concepts_places concepts_places_place_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.concepts_places + ADD CONSTRAINT concepts_places_place_id_fkey1 FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + +-- +-- Name: projects projects_timescale_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.projects + ADD CONSTRAINT projects_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + +-- +-- Name: projects projects_timescale_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.projects + ADD CONSTRAINT projects_timescale_id_fkey1 FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + +-- +-- Name: sections sections_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: sections sections_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.sections + ADD CONSTRAINT sections_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: strat_names_places strat_names_places_place_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_place_id_fkey FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + +-- +-- Name: strat_names_places strat_names_places_place_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_place_id_fkey1 FOREIGN KEY (place_id) REFERENCES macrostrat.places(place_id) ON DELETE CASCADE; + + +-- +-- Name: strat_names_places strat_names_places_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_names_places strat_names_places_strat_name_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_names_places + ADD CONSTRAINT strat_names_places_strat_name_id_fkey1 FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_child_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_child_fkey FOREIGN KEY (child) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_child_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_child_fkey1 FOREIGN KEY (child) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_parent_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_parent_fkey FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_parent_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_parent_fkey1 FOREIGN KEY (parent) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: strat_tree strat_tree_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.strat_tree + ADD CONSTRAINT strat_tree_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: timescales_intervals timescales_intervals_interval_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_interval_id_fkey FOREIGN KEY (interval_id) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: timescales_intervals timescales_intervals_interval_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_interval_id_fkey1 FOREIGN KEY (interval_id) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: timescales_intervals timescales_intervals_timescale_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_timescale_id_fkey FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + +-- +-- Name: timescales_intervals timescales_intervals_timescale_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.timescales_intervals + ADD CONSTRAINT timescales_intervals_timescale_id_fkey1 FOREIGN KEY (timescale_id) REFERENCES macrostrat.timescales(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_econ_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_econ_id_fkey FOREIGN KEY (econ_id) REFERENCES macrostrat.econs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_econ_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_econ_id_fkey1 FOREIGN KEY (econ_id) REFERENCES macrostrat.econs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_econs unit_econs_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_econs + ADD CONSTRAINT unit_econs_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_environ_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_environ_id_fkey FOREIGN KEY (environ_id) REFERENCES macrostrat.environs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_environ_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_environ_id_fkey1 FOREIGN KEY (environ_id) REFERENCES macrostrat.environs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_ref_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_ref_id_fkey FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_ref_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_ref_id_fkey1 FOREIGN KEY (ref_id) REFERENCES macrostrat.refs(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_environs unit_environs_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_environs + ADD CONSTRAINT unit_environs_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_lith_atts unit_lith_atts_lith_att_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_lith_att_id_fkey FOREIGN KEY (lith_att_id) REFERENCES macrostrat.lith_atts(id) ON DELETE CASCADE; + + +-- +-- Name: unit_lith_atts unit_lith_atts_lith_att_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_lith_att_id_fkey1 FOREIGN KEY (lith_att_id) REFERENCES macrostrat.lith_atts(id) ON DELETE CASCADE; + + +-- +-- Name: unit_lith_atts unit_lith_atts_unit_lith_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_unit_lith_id_fkey FOREIGN KEY (unit_lith_id) REFERENCES macrostrat.unit_liths(id) ON DELETE CASCADE; + + +-- +-- Name: unit_lith_atts unit_lith_atts_unit_lith_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_lith_atts + ADD CONSTRAINT unit_lith_atts_unit_lith_id_fkey1 FOREIGN KEY (unit_lith_id) REFERENCES macrostrat.unit_liths(id) ON DELETE CASCADE; + + +-- +-- Name: unit_liths unit_liths_lith_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_lith_id_fkey FOREIGN KEY (lith_id) REFERENCES macrostrat.liths(id) ON DELETE CASCADE; + + +-- +-- Name: unit_liths unit_liths_lith_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_lith_id_fkey1 FOREIGN KEY (lith_id) REFERENCES macrostrat.liths(id) ON DELETE CASCADE; + + +-- +-- Name: unit_liths unit_liths_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_liths unit_liths_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_liths + ADD CONSTRAINT unit_liths_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_strat_names unit_strat_names_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: unit_strat_names unit_strat_names_strat_name_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_strat_name_id_fkey1 FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: unit_strat_names unit_strat_names_unit_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_unit_id_fkey FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: unit_strat_names unit_strat_names_unit_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.unit_strat_names + ADD CONSTRAINT unit_strat_names_unit_id_fkey1 FOREIGN KEY (unit_id) REFERENCES macrostrat.units(id) ON DELETE CASCADE; + + +-- +-- Name: units units_col_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_col_id_fkey FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: units units_col_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_col_id_fkey1 FOREIGN KEY (col_id) REFERENCES macrostrat.cols(id) ON DELETE CASCADE; + + +-- +-- Name: units units_fo_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_fo_fkey FOREIGN KEY (fo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: units units_fo_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_fo_fkey1 FOREIGN KEY (fo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: units units_lo_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_lo_fkey FOREIGN KEY (lo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: units units_lo_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_lo_fkey1 FOREIGN KEY (lo) REFERENCES macrostrat.intervals(id) ON DELETE CASCADE; + + +-- +-- Name: units units_section_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_section_id_fkey FOREIGN KEY (section_id) REFERENCES macrostrat.sections(id) ON DELETE CASCADE; + + +-- +-- Name: units units_section_id_fkey1; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_section_id_fkey1 FOREIGN KEY (section_id) REFERENCES macrostrat.sections(id) ON DELETE CASCADE; + + +-- +-- Name: units units_strat_name_id_fkey; Type: FK CONSTRAINT; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE ONLY macrostrat.units + ADD CONSTRAINT units_strat_name_id_fkey FOREIGN KEY (strat_name_id) REFERENCES macrostrat.strat_names(id) ON DELETE CASCADE; + + +-- +-- Name: data_roles; Type: ROW SECURITY; Schema: auth; Owner: postgres +-- + +ALTER TABLE auth.data_roles ENABLE ROW LEVEL SECURITY; + +-- +-- Name: data_roles data_roles_insert; Type: POLICY; Schema: auth; Owner: postgres +-- + +CREATE POLICY data_roles_insert ON auth.data_roles FOR INSERT WITH CHECK ((role <> ALL (ARRAY['reader'::text, 'writer'::text, 'deleter'::text, 'manager'::text]))); + + +-- +-- Name: data_roles data_roles_select; Type: POLICY; Schema: auth; Owner: postgres +-- + +CREATE POLICY data_roles_select ON auth.data_roles FOR SELECT USING (true); + + +-- +-- Name: data_roles data_roles_update; Type: POLICY; Schema: auth; Owner: postgres +-- + +CREATE POLICY data_roles_update ON auth.data_roles FOR UPDATE USING ((role <> ALL (ARRAY['reader'::text, 'writer'::text, 'deleter'::text, 'manager'::text]))); + + +-- +-- Name: user_projects manager_projects; Type: POLICY; Schema: auth; Owner: postgres +-- + +CREATE POLICY manager_projects ON auth.user_projects USING ((project IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = 'manager'::text)))) WITH CHECK ((project IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = 'manager'::text)))); + + +-- +-- Name: users secure_users; Type: POLICY; Schema: auth; Owner: postgres +-- + +CREATE POLICY secure_users ON auth.users USING ((username = macrostrat_api.get_username())) WITH CHECK ((username = macrostrat_api.get_username())); + + +-- +-- Name: user_projects; Type: ROW SECURITY; Schema: auth; Owner: postgres +-- + +ALTER TABLE auth.user_projects ENABLE ROW LEVEL SECURITY; + +-- +-- Name: users; Type: ROW SECURITY; Schema: auth; Owner: postgres +-- + +ALTER TABLE auth.users ENABLE ROW LEVEL SECURITY; + +-- +-- Name: col_groups col_group_upsert; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY col_group_upsert ON macrostrat.col_groups WITH CHECK ((project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['writer'::text, 'deleter'::text, 'manager'::text]))))); + + +-- +-- Name: col_groups; Type: ROW SECURITY; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE macrostrat.col_groups ENABLE ROW LEVEL SECURITY; + +-- +-- Name: col_groups col_groups_select; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY col_groups_select ON macrostrat.col_groups FOR SELECT USING ((project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['reader'::text, 'writer'::text, 'deleter'::text, 'manager'::text]))))); + + +-- +-- Name: cols; Type: ROW SECURITY; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; + +-- +-- Name: cols cols_select; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY cols_select ON macrostrat.cols FOR SELECT USING ((project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role)))); + + +-- +-- Name: cols cols_upsert; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY cols_upsert ON macrostrat.cols WITH CHECK ((project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['writer'::text, 'deleter'::text, 'manager'::text]))))); + + +-- +-- Name: projects; Type: ROW SECURITY; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE macrostrat.projects ENABLE ROW LEVEL SECURITY; + +-- +-- Name: projects projects_; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY projects_ ON macrostrat.projects FOR SELECT USING ((id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['reader'::text, 'writer'::text, 'deleter'::text, 'manager'::text]))))); + + +-- +-- Name: projects projects_insert; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY projects_insert ON macrostrat.projects FOR INSERT WITH CHECK (true); + + +-- +-- Name: projects projects_update; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE WITH CHECK ((id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['writer'::text, 'deleter'::text, 'manager'::text]))))); + + +-- +-- Name: units; Type: ROW SECURITY; Schema: macrostrat; Owner: postgres +-- + +ALTER TABLE macrostrat.units ENABLE ROW LEVEL SECURITY; + +-- +-- Name: units units_select; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY units_select ON macrostrat.units FOR SELECT USING ((col_id IN ( SELECT c.id + FROM macrostrat.cols c + WHERE (c.project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role)))))); + + +-- +-- Name: units units_upsert; Type: POLICY; Schema: macrostrat; Owner: postgres +-- + +CREATE POLICY units_upsert ON macrostrat.units WITH CHECK ((col_id IN ( SELECT c.id + FROM macrostrat.cols c + WHERE (c.project_id IN ( SELECT current_user_projects.project + FROM macrostrat_api.current_user_projects() current_user_projects(project, role) + WHERE (current_user_projects.role = ANY (ARRAY['writer'::text, 'deleter'::text, 'manager'::text]))))))); + + +-- +-- Name: SCHEMA auth; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT USAGE ON SCHEMA auth TO api_user; + + +-- +-- Name: SCHEMA macrostrat; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT USAGE ON SCHEMA macrostrat TO api_user; + + +-- +-- Name: SCHEMA macrostrat_api; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT USAGE ON SCHEMA macrostrat_api TO api_user; +GRANT USAGE ON SCHEMA macrostrat_api TO anon; +GRANT USAGE ON SCHEMA macrostrat_api TO authenticator; + + +-- +-- Name: FUNCTION create_user(firstname text, lastname text, pass text, username text); Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT ALL ON FUNCTION macrostrat_api.create_user(firstname text, lastname text, pass text, username text) TO authenticator; +GRANT ALL ON FUNCTION macrostrat_api.create_user(firstname text, lastname text, pass text, username text) TO anon; + + +-- +-- Name: FUNCTION login(username text, pass text); Type: ACL; Schema: macrostrat_api; Owner: postgres +-- + +GRANT ALL ON FUNCTION macrostrat_api.login(username text, pass text) TO anon; +GRANT ALL ON FUNCTION macrostrat_api.login(username text, pass text) TO authenticator; + + +-- +-- Name: TABLE data_roles; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE auth.data_roles TO api_user; + + +-- +-- Name: SEQUENCE data_roles_id_seq; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE auth.data_roles_id_seq TO api_user; + + +-- +-- Name: TABLE user_projects; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE auth.user_projects TO api_user; + + +-- +-- Name: SEQUENCE user_projects_id_seq; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE auth.user_projects_id_seq TO api_user; + + +-- +-- Name: TABLE users; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE auth.users TO api_user; + + +-- +-- Name: SEQUENCE users_id_seq; Type: ACL; Schema: auth; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE auth.users_id_seq TO api_user; + + +-- +-- Name: TABLE autocomplete; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.autocomplete TO api_user; + + +-- +-- Name: TABLE col_areas; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_areas TO api_user; + + +-- +-- Name: SEQUENCE col_areas_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_areas_id_seq TO api_user; + + +-- +-- Name: TABLE col_groups; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_groups TO api_user; + + +-- +-- Name: SEQUENCE col_groups_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_groups_id_seq TO api_user; + + +-- +-- Name: TABLE col_refs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.col_refs TO api_user; + + +-- +-- Name: SEQUENCE col_refs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.col_refs_id_seq TO api_user; + + +-- +-- Name: TABLE cols; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.cols TO api_user; + + +-- +-- Name: SEQUENCE cols_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.cols_id_seq TO api_user; + + +-- +-- Name: TABLE concepts_places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.concepts_places TO api_user; + + +-- +-- Name: TABLE econs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.econs TO api_user; + + +-- +-- Name: SEQUENCE econs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.econs_id_seq TO api_user; + + +-- +-- Name: TABLE environs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.environs TO api_user; + + +-- +-- Name: SEQUENCE environs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.environs_id_seq TO api_user; + + +-- +-- Name: TABLE grainsize; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.grainsize TO api_user; + + +-- +-- Name: SEQUENCE grainsize_grain_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.grainsize_grain_id_seq TO api_user; + + +-- +-- Name: TABLE intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.intervals TO api_user; + + +-- +-- Name: SEQUENCE intervals_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.intervals_id_seq TO api_user; + + +-- +-- Name: SEQUENCE intervals_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.intervals_new_id_seq TO api_user; + + +-- +-- Name: TABLE lith_atts; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lith_atts TO api_user; + + +-- +-- Name: SEQUENCE lith_atts_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.lith_atts_id_seq TO api_user; + + +-- +-- Name: TABLE liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.liths TO api_user; + + +-- +-- Name: SEQUENCE liths_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.liths_id_seq TO api_user; + + +-- +-- Name: TABLE lookup_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_strat_names TO api_user; + + +-- +-- Name: TABLE lookup_unit_attrs_api; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_attrs_api TO api_user; + + +-- +-- Name: TABLE lookup_unit_intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_intervals TO api_user; + + +-- +-- Name: TABLE lookup_unit_liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_unit_liths TO api_user; + + +-- +-- Name: TABLE lookup_units; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.lookup_units TO api_user; + + +-- +-- Name: SEQUENCE lookup_units_unit_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.lookup_units_unit_id_seq TO api_user; + + +-- +-- Name: TABLE measurements; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measurements TO api_user; + + +-- +-- Name: SEQUENCE measurements_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_id_seq TO api_user; + + +-- +-- Name: SEQUENCE measurements_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_new_id_seq TO api_user; + + +-- +-- Name: SEQUENCE measurements_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measurements_new_id_seq1 TO api_user; + + +-- +-- Name: TABLE measuremeta; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measuremeta TO api_user; + + +-- +-- Name: SEQUENCE measuremeta_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measuremeta_id_seq TO api_user; + + +-- +-- Name: SEQUENCE measuremeta_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measuremeta_new_id_seq TO api_user; + + +-- +-- Name: TABLE measures; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.measures TO api_user; + + +-- +-- Name: SEQUENCE measures_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.measures_new_id_seq TO api_user; + + +-- +-- Name: TABLE pbdb_collections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.pbdb_collections TO api_user; + + +-- +-- Name: TABLE pbdb_collections_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.pbdb_collections_strat_names TO api_user; + + +-- +-- Name: TABLE places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.places TO api_user; + + +-- +-- Name: SEQUENCE places_place_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.places_place_id_seq TO api_user; + + +-- +-- Name: TABLE projects; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.projects TO api_user; + + +-- +-- Name: SEQUENCE projects_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.projects_id_seq TO api_user; + + +-- +-- Name: SEQUENCE projects_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.projects_new_id_seq TO api_user; + + +-- +-- Name: TABLE refs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.refs TO api_user; + + +-- +-- Name: SEQUENCE refs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.refs_id_seq TO api_user; + + +-- +-- Name: TABLE sections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.sections TO api_user; + + +-- +-- Name: SEQUENCE sections_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.sections_id_seq TO api_user; + + +-- +-- Name: SEQUENCE sections_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.sections_new_id_seq TO api_user; + + +-- +-- Name: TABLE strat_name_footprints; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_name_footprints TO api_user; + + +-- +-- Name: TABLE strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names TO api_user; + + +-- +-- Name: SEQUENCE strat_names_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_id_seq TO api_user; + + +-- +-- Name: TABLE strat_names_meta; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names_meta TO api_user; + + +-- +-- Name: SEQUENCE strat_names_meta_concept_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_meta_concept_id_seq TO api_user; + + +-- +-- Name: SEQUENCE strat_names_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_names_new_id_seq TO api_user; + + +-- +-- Name: TABLE strat_names_places; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_names_places TO api_user; + + +-- +-- Name: TABLE strat_tree; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.strat_tree TO api_user; + + +-- +-- Name: SEQUENCE strat_tree_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_tree_id_seq TO api_user; + + +-- +-- Name: SEQUENCE strat_tree_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.strat_tree_new_id_seq1 TO api_user; + + +-- +-- Name: TABLE timescales; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.timescales TO api_user; + + +-- +-- Name: SEQUENCE timescales_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.timescales_id_seq TO api_user; + + +-- +-- Name: TABLE timescales_intervals; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.timescales_intervals TO api_user; + + +-- +-- Name: TABLE unit_econs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_econs TO api_user; + + +-- +-- Name: SEQUENCE unit_econs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_econs_id_seq TO api_user; + + +-- +-- Name: TABLE unit_environs; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_environs TO api_user; + + +-- +-- Name: SEQUENCE unit_environs_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_environs_id_seq TO api_user; + + +-- +-- Name: TABLE unit_lith_atts; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_lith_atts TO api_user; + + +-- +-- Name: SEQUENCE unit_lith_atts_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_lith_atts_id_seq TO api_user; + + +-- +-- Name: TABLE unit_liths; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_liths TO api_user; + + +-- +-- Name: SEQUENCE unit_liths_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_liths_id_seq TO api_user; + + +-- +-- Name: TABLE unit_measures; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_measures TO api_user; + + +-- +-- Name: SEQUENCE unit_measures_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_measures_id_seq TO api_user; + + +-- +-- Name: SEQUENCE unit_measures_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_measures_new_id_seq TO api_user; + + +-- +-- Name: TABLE unit_strat_names; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.unit_strat_names TO api_user; + + +-- +-- Name: SEQUENCE unit_strat_names_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_strat_names_id_seq TO api_user; + + +-- +-- Name: SEQUENCE unit_strat_names_new_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.unit_strat_names_new_id_seq TO api_user; + + +-- +-- Name: TABLE units; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.units TO api_user; + + +-- +-- Name: SEQUENCE units_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_id_seq TO api_user; + + +-- +-- Name: TABLE units_sections; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE macrostrat.units_sections TO api_user; + + +-- +-- Name: SEQUENCE units_sections_id_seq; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_sections_id_seq TO api_user; + + +-- +-- Name: SEQUENCE units_sections_new_id_seq1; Type: ACL; Schema: macrostrat; Owner: postgres +-- + +GRANT SELECT,USAGE ON SEQUENCE macrostrat.units_sections_new_id_seq1 TO api_user; + + +-- +-- PostgreSQL database dump complete +-- + From 6cb7a4602b579bb65463cffb969ff339332a8ccc Mon Sep 17 00:00:00 2001 From: Casey Idzikowski Date: Wed, 13 Apr 2022 16:13:59 +0200 Subject: [PATCH 13/13] changed policies for update to include USING keyword --- .../backend/tests/test_z_auth.py | 3 ++ .../urvogel/database/fixtures/02-auth.sql | 28 +++++++++++++++++-- .../database/fixtures/02-auth.sql | 28 +++++++++++++++++-- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/v2-transition/services/column-builder/backend/tests/test_z_auth.py b/v2-transition/services/column-builder/backend/tests/test_z_auth.py index 0b92f1d4b..9496971cf 100644 --- a/v2-transition/services/column-builder/backend/tests/test_z_auth.py +++ b/v2-transition/services/column-builder/backend/tests/test_z_auth.py @@ -108,6 +108,9 @@ def test_project_create(db): assert len(data) == 2 + res = patch(base + "/projects?id=eq.13", headers={"Authorization": f'bearer {token}','Prefer': 'return=minimal'}, data={"project": "CFP2"}) + assert res.status_code != 404 + def test_child_data(db): """ add some col-group, col and unit and see that we can access it """ headers = login(username, password) diff --git a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql index afcb69ad6..bd2dbbb9b 100644 --- a/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql +++ b/v2-transition/services/column-builder/backend/urvogel/database/fixtures/02-auth.sql @@ -280,6 +280,10 @@ WITH CHECK(TRUE); -- Updates only allowable for writer, deleter or manager CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE +USING(id IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE role IN ('writer','deleter', 'manager') +)) WITH CHECK (id IN ( SELECT project from macrostrat_api.current_user_projects() WHERE role IN ('writer','deleter', 'manager') @@ -294,7 +298,12 @@ USING (project_id IN ( WHERE role IN ('reader','writer','deleter','manager'))); -CREATE POLICY col_group_upsert ON macrostrat.col_groups +CREATE POLICY col_group_update ON macrostrat.col_groups FOR UPDATE +USING(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager'))); + +CREATE POLICY col_group_insert ON macrostrat.col_groups FOR INSERT WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() WHERE role IN ('writer', 'deleter', 'manager'))); @@ -305,7 +314,13 @@ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; CREATE POLICY cols_select ON macrostrat.cols FOR SELECT USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); -CREATE POLICY cols_upsert ON macrostrat.cols +CREATE POLICY cols_update ON macrostrat.cols for UPDATE +USING(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager') +)); + +CREATE POLICY cols_insert ON macrostrat.cols for INSERT WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() WHERE role IN ('writer', 'deleter', 'manager') @@ -320,7 +335,14 @@ USING (col_id IN ( WHERE c.project_id IN( SELECT project FROM macrostrat_api.current_user_projects()))); -CREATE POLICY units_upsert ON macrostrat.units +CREATE POLICY units_update ON macrostrat.units FOR UPDATE +USING (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager')))); + +CREATE POLICY units_insert ON macrostrat.units FOR INSERT WITH CHECK (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN( diff --git a/v2-transition/services/column-builder/database/fixtures/02-auth.sql b/v2-transition/services/column-builder/database/fixtures/02-auth.sql index f24e5c46e..077bc7228 100644 --- a/v2-transition/services/column-builder/database/fixtures/02-auth.sql +++ b/v2-transition/services/column-builder/database/fixtures/02-auth.sql @@ -281,6 +281,10 @@ WITH CHECK(TRUE); -- Updates only allowable for writer, deleter or manager CREATE POLICY projects_update ON macrostrat.projects FOR UPDATE +USING(id IN ( + SELECT project from macrostrat_api.current_user_projects() + WHERE role IN ('writer','deleter', 'manager') +)) WITH CHECK (id IN ( SELECT project from macrostrat_api.current_user_projects() WHERE role IN ('writer','deleter', 'manager') @@ -295,7 +299,12 @@ USING (project_id IN ( WHERE role IN ('reader','writer','deleter','manager'))); -CREATE POLICY col_group_upsert ON macrostrat.col_groups +CREATE POLICY col_group_update ON macrostrat.col_groups FOR UPDATE +USING(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager'))); + +CREATE POLICY col_group_insert ON macrostrat.col_groups FOR INSERT WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() WHERE role IN ('writer', 'deleter', 'manager'))); @@ -306,7 +315,13 @@ ALTER TABLE macrostrat.cols ENABLE ROW LEVEL SECURITY; CREATE POLICY cols_select ON macrostrat.cols FOR SELECT USING (project_id IN (SELECT project FROM macrostrat_api.current_user_projects())); -CREATE POLICY cols_upsert ON macrostrat.cols +CREATE POLICY cols_update ON macrostrat.cols for UPDATE +USING(project_id IN ( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager') +)); + +CREATE POLICY cols_insert ON macrostrat.cols for INSERT WITH CHECK(project_id IN ( SELECT project FROM macrostrat_api.current_user_projects() WHERE role IN ('writer', 'deleter', 'manager') @@ -321,7 +336,14 @@ USING (col_id IN ( WHERE c.project_id IN( SELECT project FROM macrostrat_api.current_user_projects()))); -CREATE POLICY units_upsert ON macrostrat.units +CREATE POLICY units_update ON macrostrat.units FOR UPDATE +USING (col_id IN ( + SELECT c.id from macrostrat.cols c + WHERE c.project_id IN( + SELECT project FROM macrostrat_api.current_user_projects() + WHERE role IN ('writer', 'deleter', 'manager')))); + +CREATE POLICY units_insert ON macrostrat.units FOR INSERT WITH CHECK (col_id IN ( SELECT c.id from macrostrat.cols c WHERE c.project_id IN(