-
Notifications
You must be signed in to change notification settings - Fork 16
Extend ENSDb migrations #1899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend ENSDb migrations #1899
Changes from all commits
e3d36f6
3fb6448
ffca224
ad6c042
8c77000
e0e4e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensdb-sdk": minor | ||
| --- | ||
|
|
||
| Added `enable_ext_pg_trgm` migration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@ensnode/ensdb-sdk": minor | ||
| --- | ||
|
|
||
| Added `manage_orphaned_ensnode_metadata` migration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| -- This migration enables the pg_trgm extension, which is used for | ||
| -- trigram-based indexing and searching in PostgreSQL. | ||
| CREATE EXTENSION IF NOT EXISTS pg_trgm; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this action also require special priviliges? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- This migration adds an event trigger to handle cleanup of orphaned records | ||
| -- in the `ensnode.metadata` table when an ENSIndexer Schema is dropped. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I note that this triggers on any schema that is not the ENSNode schema. We should document this more precisely. |
||
| -- Note: Running this migration requires superuser privileges due to | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should explicitly document what the consequence is of running this migration without superuser priviliges. |
||
| -- the use of event triggers. | ||
|
|
||
| CREATE OR REPLACE FUNCTION "ensnode"."handle_schema_dropped"() | ||
| RETURNS event_trigger | ||
| AS $$ | ||
| DECLARE | ||
| obj RECORD; | ||
| BEGIN | ||
| FOR obj IN | ||
| SELECT * | ||
| FROM pg_event_trigger_dropped_objects() | ||
| LOOP | ||
| IF obj.object_type = 'schema' | ||
| AND obj.object_name <> 'ensnode' | ||
| AND to_regclass('"ensnode"."metadata"') IS NOT NULL THEN | ||
|
|
||
| DELETE FROM "ensnode"."metadata" | ||
| WHERE "ens_indexer_schema_name" = obj.object_name; | ||
|
|
||
| END IF; | ||
| END LOOP; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
|
|
||
| DO $$ | ||
| BEGIN | ||
| CREATE EVENT TRIGGER cleanup_ensnode_metadata_on_schema_drop | ||
| ON sql_drop | ||
| WHEN TAG IN ('DROP SCHEMA') | ||
| EXECUTE FUNCTION "ensnode"."handle_schema_dropped"(); | ||
|
|
||
| EXCEPTION | ||
| WHEN insufficient_privilege THEN | ||
| -- Event trigger creation requires superuser privileges. | ||
| -- This is expected in managed PostgreSQL environments. | ||
| RAISE NOTICE | ||
| 'Event trigger "cleanup_ensnode_metadata_on_schema_drop" could not be created due to insufficient privileges. This feature requires superuser access.'; | ||
| END; | ||
|
Comment on lines
+36
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Consider replacing |
||
| $$; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| { | ||
| "id": "899ad861-685e-4639-8f31-cf4130b730e6", | ||
| "prevId": "d661dcae-f64d-4ecd-a4da-3d5783e17e2c", | ||
| "version": "7", | ||
| "dialect": "postgresql", | ||
| "tables": { | ||
| "ensnode.metadata": { | ||
| "name": "metadata", | ||
| "schema": "ensnode", | ||
| "columns": { | ||
| "ens_indexer_schema_name": { | ||
| "name": "ens_indexer_schema_name", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| }, | ||
| "key": { | ||
| "name": "key", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| }, | ||
| "value": { | ||
| "name": "value", | ||
| "type": "jsonb", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| } | ||
| }, | ||
| "indexes": {}, | ||
| "foreignKeys": {}, | ||
| "compositePrimaryKeys": { | ||
| "metadata_pkey": { | ||
| "name": "metadata_pkey", | ||
| "columns": ["ens_indexer_schema_name", "key"] | ||
| } | ||
| }, | ||
| "uniqueConstraints": {}, | ||
| "policies": {}, | ||
| "checkConstraints": {}, | ||
| "isRLSEnabled": false | ||
| } | ||
| }, | ||
| "enums": {}, | ||
| "schemas": {}, | ||
| "views": {}, | ||
| "sequences": {}, | ||
| "roles": {}, | ||
| "policies": {}, | ||
| "_meta": { | ||
| "columns": {}, | ||
| "schemas": {}, | ||
| "tables": {} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| { | ||
| "id": "1403ee88-a1d3-4192-a73c-f99b034c97b2", | ||
| "prevId": "899ad861-685e-4639-8f31-cf4130b730e6", | ||
| "version": "7", | ||
| "dialect": "postgresql", | ||
| "tables": { | ||
| "ensnode.metadata": { | ||
| "name": "metadata", | ||
| "schema": "ensnode", | ||
| "columns": { | ||
| "ens_indexer_schema_name": { | ||
| "name": "ens_indexer_schema_name", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| }, | ||
| "key": { | ||
| "name": "key", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| }, | ||
| "value": { | ||
| "name": "value", | ||
| "type": "jsonb", | ||
| "primaryKey": false, | ||
| "notNull": true | ||
| } | ||
| }, | ||
| "indexes": {}, | ||
| "foreignKeys": {}, | ||
| "compositePrimaryKeys": { | ||
| "metadata_pkey": { | ||
| "name": "metadata_pkey", | ||
| "columns": ["ens_indexer_schema_name", "key"] | ||
| } | ||
| }, | ||
| "uniqueConstraints": {}, | ||
| "policies": {}, | ||
| "checkConstraints": {}, | ||
| "isRLSEnabled": false | ||
| } | ||
| }, | ||
| "enums": {}, | ||
| "schemas": {}, | ||
| "views": {}, | ||
| "sequences": {}, | ||
| "roles": {}, | ||
| "policies": {}, | ||
| "_meta": { | ||
| "columns": {}, | ||
| "schemas": {}, | ||
| "tables": {} | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.