From 219076f036db040cb034281d668c58576c5f2f51 Mon Sep 17 00:00:00 2001 From: pranav-super Date: Mon, 5 Aug 2024 13:06:15 -0700 Subject: [PATCH] move seen sources to database Previously was in local storage, but wouldn't clear correctly on DB reset. --- .../metadata/databases/tables/tables.yaml | 1 + .../databases/tables/ui/seen_sources.yaml | 35 +++++++++++++++++++ .../Aerie/9_external_events/down.sql | 1 + .../migrations/Aerie/9_external_events/up.sql | 33 +++++++++++++++++ deployment/postgres-init-db/sql/init_ui.sql | 1 + .../sql/tables/ui/seen_sources.sql | 29 +++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml create mode 100644 deployment/postgres-init-db/sql/tables/ui/seen_sources.sql diff --git a/deployment/hasura/metadata/databases/tables/tables.yaml b/deployment/hasura/metadata/databases/tables/tables.yaml index 41aed08bb3..bd1a9b8c4a 100644 --- a/deployment/hasura/metadata/databases/tables/tables.yaml +++ b/deployment/hasura/metadata/databases/tables/tables.yaml @@ -176,3 +176,4 @@ - "!include ui/extension_roles.yaml" - "!include ui/extensions.yaml" - "!include ui/view.yaml" +- "!include ui/seen_sources.yaml" diff --git a/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml b/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml new file mode 100644 index 0000000000..4c69683015 --- /dev/null +++ b/deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml @@ -0,0 +1,35 @@ +table: + name: seen_sources + schema: ui +configuration: + custom_name: "seen_sources" +select_permissions: + - role: aerie_admin + permission: + columns: '*' + filter: {} + allow_aggregations: true + - role: user + permission: + columns: '*' + filter: {} + allow_aggregations: true + - role: viewer + permission: + columns: '*' + filter: {} + allow_aggregations: true +insert_permissions: + - role: aerie_admin + permission: + columns: '*' + check: {} +update_permissions: + - role: aerie_admin + permission: + columns: '*' + filter: {} +delete_permissions: + - role: aerie_admin + permission: + filter: {} diff --git a/deployment/hasura/migrations/Aerie/9_external_events/down.sql b/deployment/hasura/migrations/Aerie/9_external_events/down.sql index 063ed7a483..e30fc90d47 100644 --- a/deployment/hasura/migrations/Aerie/9_external_events/down.sql +++ b/deployment/hasura/migrations/Aerie/9_external_events/down.sql @@ -4,5 +4,6 @@ DROP TABLE merlin.external_event CASCADE; DROP TABLE merlin.plan_derivation_group CASCADE; DROP TABLE merlin.external_source_type CASCADE; DROP TABLE merlin.external_event_type CASCADE; +DROP TABLE ui.seen_sources CASCADE; call migrations.mark_migration_rolled_back('9'); diff --git a/deployment/hasura/migrations/Aerie/9_external_events/up.sql b/deployment/hasura/migrations/Aerie/9_external_events/up.sql index 372b4ee492..af7ce2ca03 100644 --- a/deployment/hasura/migrations/Aerie/9_external_events/up.sql +++ b/deployment/hasura/migrations/Aerie/9_external_events/up.sql @@ -313,4 +313,37 @@ AFTER DELETE ON merlin.external_source -- OWNER TO aerie; --GRANT EXECUTE ON TRIGGER cleanup_on_external_source_delete TO aerie; + + + +-- Create a table to track which sources the user has and has not seen added/removed +CREATE TABLE ui.seen_sources +( + id integer NOT NULL, + "user" text NOT NULL, + external_source_name text NOT NULL, + external_source_type text NOT NULL, + derivation_group text NOT NULL, + CONSTRAINT "user -> users.username" FOREIGN KEY ("user") + REFERENCES permissions.users (username) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +-- Ensure the id is serial +CREATE SEQUENCE ui.seen_sources_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ui.seen_sources_id_seq OWNED BY ui.seen_sources.id; +ALTER TABLE ONLY ui.seen_sources ALTER COLUMN id SET DEFAULT nextval('ui.seen_sources_id_seq'::regclass); + +-- Set primary key +ALTER TABLE ONLY ui.seen_sources + ADD CONSTRAINT seen_sources_pkey PRIMARY KEY (id); + call migrations.mark_migration_applied('9'); diff --git a/deployment/postgres-init-db/sql/init_ui.sql b/deployment/postgres-init-db/sql/init_ui.sql index 2acbb28845..e6cee6a86f 100644 --- a/deployment/postgres-init-db/sql/init_ui.sql +++ b/deployment/postgres-init-db/sql/init_ui.sql @@ -10,4 +10,5 @@ begin; \ir tables/ui/extensions.sql \ir tables/ui/extension_roles.sql \ir tables/ui/view.sql + \ir tables/ui/seen_sources.sql end; diff --git a/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql b/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql new file mode 100644 index 0000000000..c69fd96f1a --- /dev/null +++ b/deployment/postgres-init-db/sql/tables/ui/seen_sources.sql @@ -0,0 +1,29 @@ +-- Create a table to track which sources the user has and has not seen added/removed +CREATE TABLE ui.seen_sources +( + id integer NOT NULL, + "user" text NOT NULL, + external_source_name text NOT NULL, + external_source_type text NOT NULL, + derivation_group text NOT NULL, + CONSTRAINT "user -> users.username" FOREIGN KEY ("user") + REFERENCES permissions.users (username) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +-- Ensure the id is serial +CREATE SEQUENCE ui.seen_sources_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER SEQUENCE ui.seen_sources_id_seq OWNED BY ui.seen_sources.id; +ALTER TABLE ONLY ui.seen_sources ALTER COLUMN id SET DEFAULT nextval('ui.seen_sources_id_seq'::regclass); + +-- Set primary key +ALTER TABLE ONLY ui.seen_sources + ADD CONSTRAINT seen_sources_pkey PRIMARY KEY (id);