From 56c45fd1f6baf6ec36364029c4628e71312d3ebf Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 15 Mar 2022 14:00:12 -0700 Subject: [PATCH] Postgres migrations for the Elastic backend migration These are cherry picked from the elastic branch so we can run them and migrate data before moving to elastic as the primary page backend. --- apple/Omnivore-iOSRelease.entitlements | 26 +++++++++++++++++++ .../0072.do.add_elastic_page_id.sql | 15 +++++++++++ .../0072.undo.add_elastic_page_id.sql | 15 +++++++++++ .../0073.do.drop_not_null_on_article_id.sql | 9 +++++++ .../0073.undo.drop_not_null_on_article_id.sql | 9 +++++++ .../0074.do.migrate_elastic_page_id_data.sql | 14 ++++++++++ ...0074.undo.migrate_elastic_page_id_data.sql | 12 +++++++++ 7 files changed, 100 insertions(+) create mode 100644 apple/Omnivore-iOSRelease.entitlements create mode 100755 packages/db/migrations/0072.do.add_elastic_page_id.sql create mode 100755 packages/db/migrations/0072.undo.add_elastic_page_id.sql create mode 100755 packages/db/migrations/0073.do.drop_not_null_on_article_id.sql create mode 100755 packages/db/migrations/0073.undo.drop_not_null_on_article_id.sql create mode 100755 packages/db/migrations/0074.do.migrate_elastic_page_id_data.sql create mode 100755 packages/db/migrations/0074.undo.migrate_elastic_page_id_data.sql diff --git a/apple/Omnivore-iOSRelease.entitlements b/apple/Omnivore-iOSRelease.entitlements new file mode 100644 index 000000000..8cd8b83b6 --- /dev/null +++ b/apple/Omnivore-iOSRelease.entitlements @@ -0,0 +1,26 @@ + + + + + aps-environment + production + com.apple.developer.applesignin + + Default + + com.apple.developer.associated-domains + + applinks:omnivore.app + applinks:dev.omnivore.app + applinks:demo.omnivore.app + + com.apple.security.application-groups + + group.app.omnivoreapp + + keychain-access-groups + + $(AppIdentifierPrefix)app.omnivore.shared + + + diff --git a/packages/db/migrations/0072.do.add_elastic_page_id.sql b/packages/db/migrations/0072.do.add_elastic_page_id.sql new file mode 100755 index 000000000..9e14e04b0 --- /dev/null +++ b/packages/db/migrations/0072.do.add_elastic_page_id.sql @@ -0,0 +1,15 @@ +-- Type: DO +-- Name: add_elastic_page_id +-- Description: Add elastic_page_id to link/page related tables + +BEGIN; + +ALTER TABLE omnivore.article_saving_request ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.reaction ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.highlight ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.reminders ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.abuse_report ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.content_display_report ADD COLUMN elastic_page_id varchar(36); +ALTER TABLE omnivore.link_share_info ADD COLUMN elastic_page_id varchar(36); + +COMMIT; diff --git a/packages/db/migrations/0072.undo.add_elastic_page_id.sql b/packages/db/migrations/0072.undo.add_elastic_page_id.sql new file mode 100755 index 000000000..da1a5926c --- /dev/null +++ b/packages/db/migrations/0072.undo.add_elastic_page_id.sql @@ -0,0 +1,15 @@ +-- Type: UNDO +-- Name: add_elastic_page_id +-- Description: Add elastic_page_id to link/page related tables + +BEGIN; + +ALTER TABLE omnivore.article_saving_request DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.reaction DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.highlight DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.reminders DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.abuse_report DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.content_display_report DROP COLUMN elastic_page_id; +ALTER TABLE omnivore.link_share_info DROP COLUMN elastic_page_id; + +COMMIT; diff --git a/packages/db/migrations/0073.do.drop_not_null_on_article_id.sql b/packages/db/migrations/0073.do.drop_not_null_on_article_id.sql new file mode 100755 index 000000000..b4b1d6928 --- /dev/null +++ b/packages/db/migrations/0073.do.drop_not_null_on_article_id.sql @@ -0,0 +1,9 @@ +-- Type: DO +-- Name: drop_not_null_on_article_id +-- Description: Drop NOT NULL on article_id in highlights table + +BEGIN; + +ALTER TABLE omnivore.highlight ALTER COLUMN article_id DROP NOT NULL; + +COMMIT; diff --git a/packages/db/migrations/0073.undo.drop_not_null_on_article_id.sql b/packages/db/migrations/0073.undo.drop_not_null_on_article_id.sql new file mode 100755 index 000000000..d359e78e0 --- /dev/null +++ b/packages/db/migrations/0073.undo.drop_not_null_on_article_id.sql @@ -0,0 +1,9 @@ +-- Type: UNDO +-- Name: drop_not_null_on_article_id +-- Description: Drop NOT NULL on article_id in highlights table + +BEGIN; + +ALTER TABLE omnivore.highlight ALTER COLUMN article_id SET NOT NULL; + +COMMIT; diff --git a/packages/db/migrations/0074.do.migrate_elastic_page_id_data.sql b/packages/db/migrations/0074.do.migrate_elastic_page_id_data.sql new file mode 100755 index 000000000..d4e0178bb --- /dev/null +++ b/packages/db/migrations/0074.do.migrate_elastic_page_id_data.sql @@ -0,0 +1,14 @@ +-- Type: DO +-- Name: migrate_elastic_page_id_data +-- Description: Migrate elastic_page_id field from article_id in highlight and article_saving_request tables + +BEGIN; + +UPDATE omnivore.article_saving_request + SET elastic_page_id = article_id + WHERE elastic_page_id is NULL AND article_id is NOT NULL; +UPDATE omnivore.highlight + SET elastic_page_id = article_id + WHERE elastic_page_id is NULL AND article_id is NOT NULL; + +COMMIT; diff --git a/packages/db/migrations/0074.undo.migrate_elastic_page_id_data.sql b/packages/db/migrations/0074.undo.migrate_elastic_page_id_data.sql new file mode 100755 index 000000000..45c3ee67a --- /dev/null +++ b/packages/db/migrations/0074.undo.migrate_elastic_page_id_data.sql @@ -0,0 +1,12 @@ +-- Type: UNDO +-- Name: migrate_elastic_page_id_data +-- Description: Migrate elastic_page_id field from article_id in highlight and article_saving_request tables + +BEGIN; + +UPDATE omnivore.article_saving_request + SET elastic_page_id = null WHERE elastic_page_id is not NULL; +UPDATE omnivore.highlight + SET elastic_page_id = null WHERE elastic_page_id is not NULL; + +COMMIT;