From f89bc30689655c83cd5370331fec41b59d03fdb9 Mon Sep 17 00:00:00 2001 From: Emilien Date: Fri, 4 Aug 2023 16:53:05 +0200 Subject: [PATCH] Migrate data for activity targets --- .../migration.sql | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 server/src/database/migrations/20230804143700_populate_commentable_entities_for_activity_targets/migration.sql diff --git a/server/src/database/migrations/20230804143700_populate_commentable_entities_for_activity_targets/migration.sql b/server/src/database/migrations/20230804143700_populate_commentable_entities_for_activity_targets/migration.sql new file mode 100644 index 00000000000..38f9082a0bb --- /dev/null +++ b/server/src/database/migrations/20230804143700_populate_commentable_entities_for_activity_targets/migration.sql @@ -0,0 +1,20 @@ +-- This is a manually written migration to populate company and person on the activity targets based on the previous commentable id +-- This is a one time migration and should not be run again, it could also be ran as a one-off script + +UPDATE "activity_targets" as atg SET + "companyId"="commentableId" +WHERE "commentableType"='Company' +AND "commentableId" IS NOT NULL +AND NOT EXISTS ( + SELECT 1 FROM "companies" AS c + WHERE c."id" = atg."commentableId" +); + +UPDATE "activity_targets" as atg SET + "personId"="commentableId" +WHERE "commentableType"='Person' +AND "commentableId" IS NOT NULL +AND NOT EXISTS ( + SELECT 1 FROM "people" AS p + WHERE p."id" = atg."commentableId" +); \ No newline at end of file