Skip to content
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

fix: v0.52.5 migrations #1094

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions sql/migrations/20241121142159_v0.52.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ CREATE INDEX "RetryQueueItem_isQueued_tenantId_retryAfter_idx" ON "RetryQueueIte
CREATE TYPE "WorkflowTriggerCronRefMethods" AS ENUM ('DEFAULT', 'API');
-- Create enum type "WorkflowTriggerScheduledRefMethods"
CREATE TYPE "WorkflowTriggerScheduledRefMethods" AS ENUM ('DEFAULT', 'API');
-- Modify "WorkflowTriggerCronRef" table
ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "name" text NULL, ADD COLUMN "id" uuid NOT NULL, ADD COLUMN "method" "WorkflowTriggerCronRefMethods" NOT NULL DEFAULT 'DEFAULT', ADD CONSTRAINT "WorkflowTriggerCronRef_parentId_cron_name_key" UNIQUE ("parentId", "cron", "name");

-- Step 1: Add the new columns with "id" as nullable
ALTER TABLE "WorkflowTriggerCronRef"
ADD COLUMN "name" text NULL,
ADD COLUMN "id" uuid NULL,
ADD COLUMN "method" "WorkflowTriggerCronRefMethods" NOT NULL DEFAULT 'DEFAULT',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How big is WorkflowTriggerCronRef ? we will probably need to create an index on the id after we add it because once we alter table to be not null I presume that will perform a seq scan on the table to check for NULL

Between the update and the alter it's possible for someone to add a row into the table that will break the next step. It would be best to update the rows, lock the table, update any new rows and then alter the table in that transaction.

ADD CONSTRAINT "WorkflowTriggerCronRef_parentId_cron_name_key" UNIQUE ("parentId", "cron", "name");

-- Step 2: Populate "id" column with UUIDs for existing rows
UPDATE "WorkflowTriggerCronRef"
SET "id" = gen_random_uuid()
WHERE "id" IS NULL;

-- Step 3: Alter "id" column to be NOT NULL
ALTER TABLE "WorkflowTriggerCronRef"
ALTER COLUMN "id" SET NOT NULL;

UPDATE "WorkflowTriggerCronRef" SET "name" = '' WHERE "name" IS NULL;

Expand Down
6 changes: 3 additions & 3 deletions sql/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
h1:sKzk6H+hzjxCLeAk/CkTouxbldj14qwUpoKyby94tN0=
h1:Wss8IkuJYR8J4IJ6CRNFuue+s1DgpMvGj2L+ErfzrwI=
20240115180414_init.sql h1:Ef3ZyjAHkmJPdGF/dEWCahbwgcg6uGJKnDxW2JCRi2k=
20240122014727_v0_6_0.sql h1:o/LdlteAeFgoHJ3e/M4Xnghqt9826IE/Y/h0q95Acuo=
20240126235456_v0_7_0.sql h1:KiVzt/hXgQ6esbdC6OMJOOWuYEXmy1yeCpmsVAHTFKs=
Expand Down Expand Up @@ -75,5 +75,5 @@ h1:sKzk6H+hzjxCLeAk/CkTouxbldj14qwUpoKyby94tN0=
20241029122625_v0.51.0.sql h1:nOa4FqmZxSh1yBOJyduX+j15gQavjizTn660wyXjhNk=
20241107162939_v0.51.2.sql h1:qtnUITelb0kzAazo99gdTzejmQeOiE8NTP8b8bpQuF0=
20241114175346_v0.51.3.sql h1:ZbpRJsCmt6098ilZ3LtOk9LXRzuuwiznXPJmSkZSRpg=
20241121142159_v0.52.0.sql h1:fQdRQTxg2PiuFWbXJ9M4jxJLJsOkuWm5wfIuv8UPBVY=
20241204191714_v0.52.5.sql h1:aN6nxVv2oT3vCoxVw33nspjxlx/y3YLvyG6gWtmRGQI=
20241121142159_v0.52.0.sql h1:8oIy/D+oN92eMKWJT7QeA7yujewNxpSLLDJhed6wwZY=
20241204191714_v0.52.5.sql h1:6oJgHJynK+YtwQoD/VnqiCMda409K96A4Oq2l8h3dQ0=
Loading