Skip to content

Commit

Permalink
move seen sources to database
Browse files Browse the repository at this point in the history
Previously was in local storage, but wouldn't clear correctly on DB reset.
  • Loading branch information
pranav-super committed Aug 5, 2024
1 parent c2afd3d commit 219076f
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions deployment/hasura/metadata/databases/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,4 @@
- "!include ui/extension_roles.yaml"
- "!include ui/extensions.yaml"
- "!include ui/view.yaml"
- "!include ui/seen_sources.yaml"
35 changes: 35 additions & 0 deletions deployment/hasura/metadata/databases/tables/ui/seen_sources.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
Original file line number Diff line number Diff line change
Expand Up @@ -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');
33 changes: 33 additions & 0 deletions deployment/hasura/migrations/Aerie/9_external_events/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');
1 change: 1 addition & 0 deletions deployment/postgres-init-db/sql/init_ui.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
29 changes: 29 additions & 0 deletions deployment/postgres-init-db/sql/tables/ui/seen_sources.sql
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 219076f

Please sign in to comment.