add data migration script

This commit is contained in:
Hongbo Wu 2024-03-27 18:50:08 +08:00
parent 6361759eef
commit ffed903bb9
2 changed files with 25 additions and 0 deletions

View file

@ -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;

View file

@ -0,0 +1,7 @@
-- Type: UNDO
-- Name: migrate_webhooks_and_exporter
-- Description: Migrate data from webhooks and exporters to rules
BEGIN;
COMMIT;