From ffed903bb93a1c9ae4164e83f32c8c921dfd530c Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 27 Mar 2024 18:50:08 +0800 Subject: [PATCH] add data migration script --- .../0171.do.migrate_webhooks_and_exporter.sql | 18 ++++++++++++++++++ ...0171.undo.migrate_webhooks_and_exporter.sql | 7 +++++++ 2 files changed, 25 insertions(+) create mode 100755 packages/db/migrations/0171.do.migrate_webhooks_and_exporter.sql create mode 100755 packages/db/migrations/0171.undo.migrate_webhooks_and_exporter.sql diff --git a/packages/db/migrations/0171.do.migrate_webhooks_and_exporter.sql b/packages/db/migrations/0171.do.migrate_webhooks_and_exporter.sql new file mode 100755 index 000000000..6c0b691dc --- /dev/null +++ b/packages/db/migrations/0171.do.migrate_webhooks_and_exporter.sql @@ -0,0 +1,18 @@ +-- Type: DO +-- Name: migrate_webhooks_and_exporter +-- Description: Migrate data from webhooks and exporters to rules + +BEGIN; + +-- Migrate webhooks to rules +INSERT INTO omnivore.rules (user_id, name, filter, actions, enabled, created_at, updated_at, event_types) +SELECT user_id, 'webhook', 'in:all', jsonb_build_array(jsonb_build_object('type', 'WEBHOOK', 'params', jsonb_build_array(url))), enabled, created_at, updated_at, event_types +FROM omnivore.webhooks; + +-- Migrate exporters to rules +INSERT INTO omnivore.rules (user_id, name, filter, actions, enabled, created_at, updated_at, event_types) +SELECT user_id, 'export', 'in:all', jsonb_build_array(jsonb_build_object('type', 'EXPORT', 'params', jsonb_build_array(name))), enabled, created_at, updated_at, '{PAGE_CREATED,PAGE_UPDATED,HIGHLIGHT_CREATED,LABEL_CREATED}' +FROM omnivore.integrations +WHERE type = 'EXPORT'; + +COMMIT; diff --git a/packages/db/migrations/0171.undo.migrate_webhooks_and_exporter.sql b/packages/db/migrations/0171.undo.migrate_webhooks_and_exporter.sql new file mode 100755 index 000000000..1a5755bb4 --- /dev/null +++ b/packages/db/migrations/0171.undo.migrate_webhooks_and_exporter.sql @@ -0,0 +1,7 @@ +-- Type: UNDO +-- Name: migrate_webhooks_and_exporter +-- Description: Migrate data from webhooks and exporters to rules + +BEGIN; + +COMMIT;