From 3c6736af0599c15409c1a8a5419925daf6dd7cd2 Mon Sep 17 00:00:00 2001 From: Sean Reilly Date: Fri, 22 Nov 2024 19:04:12 -0800 Subject: [PATCH 1/3] update the migration so it is more performant when we have many deadlocks --- sql/migrations/20241121142159_v0.52.0.sql | 424 ++++++++++++++++++++-- sql/migrations/atlas.sum | 8 +- 2 files changed, 390 insertions(+), 42 deletions(-) diff --git a/sql/migrations/20241121142159_v0.52.0.sql b/sql/migrations/20241121142159_v0.52.0.sql index 50e65fdbb..9fe914094 100644 --- a/sql/migrations/20241121142159_v0.52.0.sql +++ b/sql/migrations/20241121142159_v0.52.0.sql @@ -1,19 +1,316 @@ -- atlas:txmode none + + +-- 'Creating an updatedAt index that will be useful later'; +create index CONCURRENTLY IF NOT EXISTS "StepRun_updatedAt_idx" on "StepRun" ("updatedAt"); + + +DO $$ + +DECLARE + retry_count INT := 0; + max_retries INT := 40; + sleep_interval INT := 30000; + rec RECORD; + sql_statement TEXT; + newest_record RECORD; +BEGIN + + SET LOCAL lock_timeout = '60s'; + + IF EXISTS ( + SELECT 1 + FROM information_schema.tables + WHERE table_name = 'StepRun_new' + ) THEN + RAISE NOTICE 'StepRun_new Present!'; + ELSE + RAISE NOTICE 'StepRun_new Not Present! Creating StepRun_new'; + + + CREATE TABLE "StepRun_new" ( + "id" uuid NOT NULL, + "createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "deletedAt" timestamp(3), + "tenantId" uuid NOT NULL, + "jobRunId" uuid NOT NULL, + "stepId" uuid NOT NULL, + "order" BIGSERIAL, + "workerId" uuid, + "tickerId" uuid, + "status" "StepRunStatus" NOT NULL DEFAULT 'PENDING'::"StepRunStatus", + "input" jsonb, + "output" jsonb, + "requeueAfter" timestamp(3) without time zone, + "scheduleTimeoutAt" timestamp(3) without time zone, + "error" text, + "startedAt" timestamp(3) without time zone, + "finishedAt" timestamp(3) without time zone, + "timeoutAt" timestamp(3) without time zone, + "cancelledAt" timestamp(3) without time zone, + "cancelledReason" text, + "cancelledError" text, + "inputSchema" jsonb, + "callerFiles" jsonb, + "gitRepoBranch" text, + "retryCount" integer NOT NULL DEFAULT 0, + "semaphoreReleased" boolean NOT NULL DEFAULT false, + "queue" text NOT NULL DEFAULT 'default'::text, + "priority" integer, + "internalRetryCount" INTEGER NOT NULL DEFAULT 0, + "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, + + PRIMARY KEY ( "status", "id"), + UNIQUE ("status", "identityId") + + ) PARTITION BY LIST ("status"); + + + RAISE NOTICE 'Created table "StepRun_new"'; + + + CREATE TABLE "StepRun_volatile" PARTITION OF "StepRun_new" + FOR VALUES IN ('PENDING','PENDING_ASSIGNMENT','ASSIGNED','RUNNING','CANCELLING') + WITH (fillfactor = 50); + + CREATE TABLE "StepRun_stable" PARTITION OF "StepRun_new" + FOR VALUES IN ('FAILED','CANCELLED','SUCCEEDED') WITH (fillfactor = 100); + + RAISE NOTICE 'Created partitions for "StepRun_new"'; + + RAISE NOTICE 'Inserting data into "StepRun_new"'; + + INSERT INTO "StepRun_new" SELECT * FROM "StepRun" ; + + RAISE NOTICE 'Inserted data into "StepRun_new"'; + + + + RAISE NOTICE 'Inserted data into "StepRun_new"'; + + RAISE NOTICE 'Creating indexes for "StepRun_new"'; + ALTER INDEX IF EXISTS "StepRun_createdAt_idx" RENAME TO "StepRun_createdAt_idx_old"; + ALTER INDEX IF EXISTS "StepRun_deletedAt_idx" RENAME TO "StepRun_deletedAt_idx_old"; + ALTER INDEX IF EXISTS "StepRun_updatedAt_idx" RENAME TO "StepRun_updatedAt_idx_old"; + + ALTER INDEX IF EXISTS "StepRun_id_tenantId_idx" RENAME TO "StepRun_id_tenantId_idx_old"; + ALTER INDEX IF EXISTS "StepRun_jobRunId_status_idx" RENAME TO "StepRun_jobRunId_status_idx_old"; + ALTER INDEX IF EXISTS "StepRun_jobRunId_tenantId_order_idx" RENAME TO "StepRun_jobRunId_tenantId_order_idx_old"; + ALTER INDEX IF EXISTS "StepRun_stepId_idx" RENAME TO "StepRun_stepId_idx_old"; + ALTER INDEX IF EXISTS "StepRun_tenantId_idx" RENAME TO "StepRun_tenantId_idx_old"; + ALTER INDEX IF EXISTS "StepRun_workerId_idx" RENAME TO "StepRun_workerId_idx_old"; + ALTER INDEX IF EXISTS "StepRun_jobRunId_status_tenantId_idx" RENAME TO "StepRun_jobRunId_status_tenantId_idx_old"; + + CREATE INDEX "StepRun_createdAt_idx" ON "StepRun_new" ("createdAt"); + CREATE INDEX "StepRun_deletedAt_idx" ON "StepRun_new" ("deletedAt"); + CREATE INDEX "StepRun_updatedAt_idx" ON "StepRun_new" ("updatedAt"); + CREATE INDEX "StepRun_id_tenantId_idx" ON "StepRun_new" ("id", "tenantId"); + CREATE INDEX "StepRun_jobRunId_status_idx" ON "StepRun_new" ("jobRunId", "status"); + CREATE INDEX "StepRun_jobRunId_tenantId_order_idx" ON "StepRun_new" ("jobRunId", "tenantId", "order"); + CREATE INDEX "StepRun_stepId_idx" ON "StepRun_new" ("stepId"); + CREATE INDEX "StepRun_tenantId_idx" ON "StepRun_new" ("tenantId"); + CREATE INDEX "StepRun_workerId_idx" ON "StepRun_new" ("workerId"); + CREATE INDEX "StepRun_status_tenantId_idx" ON "StepRun_new" ("status", "tenantId"); + CREATE INDEX "StepRun_id_status" ON "StepRun" ("id", "status"); + CREATE INDEX "StepRun_jobRunId_status_tenantId_idx" ON "StepRun" ("jobRunId", "status", "tenantId") WHERE (status = 'PENDING'::"StepRunStatus"); + + RAISE NOTICE 'Created indexes for "StepRun_new"'; + + RAISE NOTICE 'StepRun_new table created successfully now we try and swap the tables'; + + END IF; + + WHILE retry_count < max_retries LOOP + BEGIN + + + + + + + RAISE NOTICE 'Locking tables'; + LOCK TABLE "StepRun" IN ACCESS EXCLUSIVE MODE; + -- LOCK TABLE "StepRun_new" IN ACCESS EXCLUSIVE MODE; + + + RAISE NOTICE 'Locked tables'; + + + + + + RAISE NOTICE 'Checking for data since the last select'; + + + INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( + SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" + ); + ALTER TABLE "StepRun_volatile" + SET (autovacuum_vacuum_threshold = '1000', + autovacuum_vacuum_scale_factor = '0.01', + autovacuum_analyze_threshold = '500', + autovacuum_analyze_scale_factor = '0.01'); + + + RAISE NOTICE 'Renaming tables and copying any new data'; + + INSERT INTO "StepRun_new" + SELECT * + FROM "StepRun" + WHERE "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") + AND NOT EXISTS ( + SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" + ); + + ALTER TABLE "StepRun" RENAME TO "StepRun_old"; + ALTER TABLE "StepRun_new" RENAME TO "StepRun"; + + + + + --- Drop index "StepRun_updatedAt_idx" from table: "StepRun" + DROP INDEX IF EXISTS "StepRun_updatedAt_idx"; + + + + + + RAISE NOTICE 'Migration successful EXIT'; + COMMIT; + EXIT; +EXCEPTION + WHEN OTHERS THEN + RAISE NOTICE 'Migration failed, retrying...'; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + retry_count := retry_count + 1; + RAISE NOTICE 'Attempt %', retry_count; + + if retry_count < max_retries then + -- Sleep for a bit before retrying + + PERFORM pg_sleep(sleep_interval / 1000.0); + ELSE + -- Exit the loop if max retries are reached + RAISE EXCEPTION 'Migration failed after % retries', retry_count; + END IF; + + END; + END LOOP; +END $$; + + + +DECLARE + retry_count INT := 0; + max_retries INT := 40; + sleep_interval INT := 30000; + rec RECORD; + sql_statement TEXT; + newest_record RECORD; +BEGIN + + + + LOCK TABLE "_StepRunOrder" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "StepRunResultArchive" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "LogLine" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "WorkflowTriggerScheduledRef" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "WorkflowRun" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "StreamEvent" IN ACCESS EXCLUSIVE MODE; + RAISE NOTICE 'Renamed tables now we try and create the triggers'; + + RAISE NOTICE 'Modify Workflow Run table while we have it locked'; + --- Modify "WorkflowRun" table + ALTER TABLE "WorkflowRun" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; + + + + FOR rec IN + SELECT + conname AS constraint_name, + conrelid::regclass AS referencing_table, + a.attname AS referencing_column, + confrelid::regclass AS referenced_table, + af.attname AS referenced_column + FROM + pg_constraint c + JOIN + pg_attribute a ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid + JOIN + pg_attribute af ON af.attnum = ANY(c.confkey) AND af.attrelid = c.confrelid + WHERE + confrelid = '"StepRun_old"'::regclass + AND contype = 'f' + LOOP + + RAISE NOTICE 'Referencing column: %, Referenced table: %, Referenced column: %', rec.referencing_column, rec.referenced_table, rec.referenced_column; + + sql_statement = 'CREATE OR REPLACE FUNCTION ' || 'StepRun' || rec.referencing_column || '_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."'|| rec.referencing_column || '" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "' || rec.referenced_column || '" = NEW."' || rec.referencing_column || '" + ) THEN + RAISE EXCEPTION ''Foreign key violation: ' || 'StepRun' || ' with ' || rec.referenced_column || ' = % does not exist.'', NEW."' || rec.referencing_column || '"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql;'; + + RAISE NOTICE 'Executing: %', sql_statement; + + EXECUTE sql_statement; + + RAISE NOTICE 'Created trigger function for %', rec.constraint_name; + + sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_insert_trigger" + BEFORE INSERT ON ' || rec.referencing_table || ' + FOR EACH ROW + EXECUTE FUNCTION ' || 'StepRun'||rec.referencing_column|| '_fk_trigger_function();'; + RAISE NOTICE 'Executing: %', sql_statement; + EXECUTE sql_statement; + + sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_update_trigger" + BEFORE UPDATE ON ' || rec.referencing_table || ' + FOR EACH ROW + EXECUTE FUNCTION ' || 'StepRun' || rec.referencing_column|| '_fk_trigger_function();'; + RAISE NOTICE 'Executing: %', sql_statement; + + + + EXECUTE sql_statement; + + sql_statement = 'ALTER TABLE ' || rec.referencing_table || ' DROP CONSTRAINT "' || rec.constraint_name || '"'; + RAISE NOTICE 'Executing: %', sql_statement; + EXECUTE sql_statement; + + + END LOOP; + +END; +-- 1. Create a new "Event" table with the desired schema (including the new identityId column) +-- atlas:txmode none + + + -- 'Creating an updatedAt index that will be useful later'; create index CONCURRENTLY IF NOT EXISTS "StepRun_updatedAt_idx" on "StepRun" ("updatedAt"); -- 'Created index'; DO $$ DECLARE retry_count INT := 0; - max_retries INT := 10; + max_retries INT := 20; sleep_interval INT := 5000; rec RECORD; sql_statement TEXT; newest_record RECORD; BEGIN - WHILE retry_count < max_retries LOOP - BEGIN + SET LOCAL lock_timeout = '30s'; @@ -49,8 +346,13 @@ BEGIN "queue" text NOT NULL DEFAULT 'default'::text, "priority" integer, "internalRetryCount" INTEGER NOT NULL DEFAULT 0, - PRIMARY KEY ( "status", "id") + "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, + + PRIMARY KEY ( "status", "id"), + UNIQUE ("status", "identityId") + ) PARTITION BY LIST ("status"); + RAISE NOTICE 'Created table "StepRun_new"'; @@ -98,10 +400,21 @@ BEGIN CREATE INDEX "StepRun_workerId_idx" ON "StepRun_new" ("workerId"); CREATE INDEX "StepRun_status_tenantId_idx" ON "StepRun_new" ("status", "tenantId"); +-- Create index "StepRun_id_key" to table: "StepRun" +CREATE UNIQUE INDEX IF NOT EXISTS "StepRun_new_id_key" ON "StepRun_new" ("id", "status"); +-- Create index "StepRun_jobRunId_status_tenantId_idx" to table: "StepRun" +CREATE INDEX IF NOT EXISTS "StepRun_new_jobRunId_status_tenantId_idx" ON "StepRun_new" ("jobRunId", "status", "tenantId") WHERE (status = 'PENDING'::"StepRunStatus"); + RAISE NOTICE 'Created indexes for "StepRun_new"'; - RAISE NOTICE 'Created indexes for "StepRun_new"'; + RAISE NOTICE 'StepRun_new table created successfully now we try and swap the tables'; - RAISE NOTICE 'Checking for data since the last select'; + WHILE retry_count < max_retries LOOP + BEGIN + + + + + RAISE NOTICE 'Checking for data since the last select'; INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( @@ -116,8 +429,19 @@ BEGIN RAISE NOTICE 'Renaming tables and copying any new data'; BEGIN - LOCK TABLE "StepRun" IN SHARE MODE; - LOCK TABLE "StepRun_new" IN SHARE MODE; + LOCK TABLE "StepRun" IN ACCESS EXCLUSIVE MODE; + + + LOCK TABLE "_StepRunOrder" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "StepRunResultArchive" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "LogLine" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "WorkflowTriggerScheduledRef" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "WorkflowRun" IN ACCESS EXCLUSIVE MODE; + LOCK TABLE "StreamEvent" IN ACCESS EXCLUSIVE MODE; + + + + INSERT INTO "StepRun_new" SELECT * @@ -128,10 +452,13 @@ BEGIN ); + + + ALTER TABLE "StepRun" RENAME TO "StepRun_old"; ALTER TABLE "StepRun_new" RENAME TO "StepRun"; - END; + RAISE NOTICE 'Renamed tables now we try and create the triggers'; FOR rec IN SELECT @@ -197,8 +524,9 @@ BEGIN END LOOP; + END; - + RAISE NOTICE 'Migration successful EXIT'; EXIT; @@ -206,39 +534,59 @@ BEGIN WHEN OTHERS THEN RAISE NOTICE 'Migration failed, retrying...'; RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; - ROLLBACK; + -- ROLLBACK; retry_count := retry_count + 1; RAISE NOTICE 'Attempt %', retry_count; PERFORM pg_sleep(sleep_interval / 1000.0); END; END LOOP; +END $$; +CREATE TABLE "Event_new" ( + LIKE "Event" INCLUDING CONSTRAINTS, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY +); - IF retry_count = max_retries THEN - RAISE EXCEPTION 'Migration failed after % attempts.', max_retries; - END IF; - RAISE NOTICE 'Migration successful COMMIT'; - DROP TABLE "StepRun_old"; - COMMIT; -END $$; +INSERT INTO "Event_new" SELECT * FROM "Event"; --- Drop index "StepRun_updatedAt_idx" from table: "StepRun" -DROP INDEX "StepRun_updatedAt_idx"; --- Create index "StepRun_id_key" to table: "StepRun" -CREATE UNIQUE INDEX "StepRun_id_key" ON "StepRun" ("id", "status"); --- Create index "StepRun_jobRunId_status_tenantId_idx" to table: "StepRun" -CREATE INDEX "StepRun_jobRunId_status_tenantId_idx" ON "StepRun" ("jobRunId", "status", "tenantId") WHERE (status = 'PENDING'::"StepRunStatus"); - - --- Modify "StepRun" table -ALTER TABLE "StepRun" ADD COLUMN "identityId" bigserial NOT NULL, ADD CONSTRAINT "step_run_identity_id_unique" UNIQUE ("identityId", "status"); --- Modify "Event" table -ALTER TABLE "Event" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; --- Modify "JobRun" table -ALTER TABLE "JobRun" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; --- Modify "JobRunLookupData" table -ALTER TABLE "JobRunLookupData" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; --- Modify "WorkflowRun" table -ALTER TABLE "WorkflowRun" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; --- Modify "WorkflowRunTriggeredBy" table -ALTER TABLE "WorkflowRunTriggeredBy" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; \ No newline at end of file +ALTER TABLE "Event" RENAME TO "Event_backup"; +ALTER TABLE "Event_new" RENAME TO "Event"; + +DROP TABLE "Event_backup" CASCADE; + + +CREATE TABLE "JobRun_new" ( + LIKE "JobRun" INCLUDING CONSTRAINTS, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY +); + +INSERT INTO "JobRun_new" SELECT * FROM "JobRun"; + +ALTER TABLE "JobRun" RENAME TO "JobRun_backup"; +ALTER TABLE "JobRun_new" RENAME TO "JobRun"; + +DROP TABLE "JobRun_backup" CASCADE; +CREATE TABLE "JobRunLookupData_new" ( + LIKE "JobRunLookupData" INCLUDING CONSTRAINTS, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY +); + +INSERT INTO "JobRunLookupData_new" SELECT * FROM "JobRunLookupData"; + +ALTER TABLE "JobRunLookupData" RENAME TO "JobRunLookupData_backup"; +ALTER TABLE "JobRunLookupData_new" RENAME TO "JobRunLookupData"; + +DROP TABLE "JobRunLookupData_backup" CASCADE; +CREATE TABLE "WorkflowRunTriggeredBy_new" ( + LIKE "WorkflowRunTriggeredBy" INCLUDING CONSTRAINTS, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY +); + +INSERT INTO "WorkflowRunTriggeredBy_new" SELECT * FROM "WorkflowRunTriggeredBy"; + +ALTER TABLE "WorkflowRunTriggeredBy" RENAME TO "WorkflowRunTriggeredBy_backup"; +ALTER TABLE "WorkflowRunTriggeredBy_new" RENAME TO "WorkflowRunTriggeredBy"; + +DROP TABLE "WorkflowRunTriggeredBy_backup" CASCADE; + +DROP TABLE "StepRun_old" CASCADE; \ No newline at end of file diff --git a/sql/migrations/atlas.sum b/sql/migrations/atlas.sum index e8e498071..7dceebb91 100644 --- a/sql/migrations/atlas.sum +++ b/sql/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:dC6PwKKRlUBxyRThtmBxRZoUsxdOH3dTos0926Yij54= +h1:5vsqrOtNUXuZIoT3KaU05MfC9antMP9WWEqIeUZO5PU= 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= @@ -75,6 +75,6 @@ h1:dC6PwKKRlUBxyRThtmBxRZoUsxdOH3dTos0926Yij54= 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:JGnuMOg3QTs2u9mcgMGA1PNqjrA64zyHpFVm9IRCkAg= -20241121153627_v0.52.1.sql h1:6ZHMeSYHjo1MRS1qDJH6RzNKdR46YQzdJ9DxCm56IlM= -20241121195232_v0.52.2.sql h1:ExHYa+nRVVff5Gb1dvRwHyC98eFRVA0Vsrg/bd96hYE= +20241121142159_v0.52.0.sql h1:2jle/v6mwceeuEBArHKXmZXH3ztHZi8VwcovaOAtPjY= +20241121153627_v0.52.1.sql h1:zs9qMJZE1PpP106fZ1pbiHZbrJuzlcU4wHaeJURQbzc= +20241121195232_v0.52.2.sql h1:toMEPVfz92ULyODPVBlMHJcWI+pJpLDzx86ip0oi+AY= From 5956af38dfd51b8bb246d2a8df91e96f8bc0dd4c Mon Sep 17 00:00:00 2001 From: Sean Reilly Date: Fri, 22 Nov 2024 19:06:59 -0800 Subject: [PATCH 2/3] remove extra copypasta --- sql/migrations/20241121142159_v0.52.0.sql | 296 ---------------------- sql/migrations/atlas.sum | 8 +- 2 files changed, 4 insertions(+), 300 deletions(-) diff --git a/sql/migrations/20241121142159_v0.52.0.sql b/sql/migrations/20241121142159_v0.52.0.sql index 9fe914094..64acc3de5 100644 --- a/sql/migrations/20241121142159_v0.52.0.sql +++ b/sql/migrations/20241121142159_v0.52.0.sql @@ -2,302 +2,6 @@ --- 'Creating an updatedAt index that will be useful later'; -create index CONCURRENTLY IF NOT EXISTS "StepRun_updatedAt_idx" on "StepRun" ("updatedAt"); - - -DO $$ - -DECLARE - retry_count INT := 0; - max_retries INT := 40; - sleep_interval INT := 30000; - rec RECORD; - sql_statement TEXT; - newest_record RECORD; -BEGIN - - SET LOCAL lock_timeout = '60s'; - - IF EXISTS ( - SELECT 1 - FROM information_schema.tables - WHERE table_name = 'StepRun_new' - ) THEN - RAISE NOTICE 'StepRun_new Present!'; - ELSE - RAISE NOTICE 'StepRun_new Not Present! Creating StepRun_new'; - - - CREATE TABLE "StepRun_new" ( - "id" uuid NOT NULL, - "createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" timestamp(3), - "tenantId" uuid NOT NULL, - "jobRunId" uuid NOT NULL, - "stepId" uuid NOT NULL, - "order" BIGSERIAL, - "workerId" uuid, - "tickerId" uuid, - "status" "StepRunStatus" NOT NULL DEFAULT 'PENDING'::"StepRunStatus", - "input" jsonb, - "output" jsonb, - "requeueAfter" timestamp(3) without time zone, - "scheduleTimeoutAt" timestamp(3) without time zone, - "error" text, - "startedAt" timestamp(3) without time zone, - "finishedAt" timestamp(3) without time zone, - "timeoutAt" timestamp(3) without time zone, - "cancelledAt" timestamp(3) without time zone, - "cancelledReason" text, - "cancelledError" text, - "inputSchema" jsonb, - "callerFiles" jsonb, - "gitRepoBranch" text, - "retryCount" integer NOT NULL DEFAULT 0, - "semaphoreReleased" boolean NOT NULL DEFAULT false, - "queue" text NOT NULL DEFAULT 'default'::text, - "priority" integer, - "internalRetryCount" INTEGER NOT NULL DEFAULT 0, - "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, - - PRIMARY KEY ( "status", "id"), - UNIQUE ("status", "identityId") - - ) PARTITION BY LIST ("status"); - - - RAISE NOTICE 'Created table "StepRun_new"'; - - - CREATE TABLE "StepRun_volatile" PARTITION OF "StepRun_new" - FOR VALUES IN ('PENDING','PENDING_ASSIGNMENT','ASSIGNED','RUNNING','CANCELLING') - WITH (fillfactor = 50); - - CREATE TABLE "StepRun_stable" PARTITION OF "StepRun_new" - FOR VALUES IN ('FAILED','CANCELLED','SUCCEEDED') WITH (fillfactor = 100); - - RAISE NOTICE 'Created partitions for "StepRun_new"'; - - RAISE NOTICE 'Inserting data into "StepRun_new"'; - - INSERT INTO "StepRun_new" SELECT * FROM "StepRun" ; - - RAISE NOTICE 'Inserted data into "StepRun_new"'; - - - - RAISE NOTICE 'Inserted data into "StepRun_new"'; - - RAISE NOTICE 'Creating indexes for "StepRun_new"'; - ALTER INDEX IF EXISTS "StepRun_createdAt_idx" RENAME TO "StepRun_createdAt_idx_old"; - ALTER INDEX IF EXISTS "StepRun_deletedAt_idx" RENAME TO "StepRun_deletedAt_idx_old"; - ALTER INDEX IF EXISTS "StepRun_updatedAt_idx" RENAME TO "StepRun_updatedAt_idx_old"; - - ALTER INDEX IF EXISTS "StepRun_id_tenantId_idx" RENAME TO "StepRun_id_tenantId_idx_old"; - ALTER INDEX IF EXISTS "StepRun_jobRunId_status_idx" RENAME TO "StepRun_jobRunId_status_idx_old"; - ALTER INDEX IF EXISTS "StepRun_jobRunId_tenantId_order_idx" RENAME TO "StepRun_jobRunId_tenantId_order_idx_old"; - ALTER INDEX IF EXISTS "StepRun_stepId_idx" RENAME TO "StepRun_stepId_idx_old"; - ALTER INDEX IF EXISTS "StepRun_tenantId_idx" RENAME TO "StepRun_tenantId_idx_old"; - ALTER INDEX IF EXISTS "StepRun_workerId_idx" RENAME TO "StepRun_workerId_idx_old"; - ALTER INDEX IF EXISTS "StepRun_jobRunId_status_tenantId_idx" RENAME TO "StepRun_jobRunId_status_tenantId_idx_old"; - - CREATE INDEX "StepRun_createdAt_idx" ON "StepRun_new" ("createdAt"); - CREATE INDEX "StepRun_deletedAt_idx" ON "StepRun_new" ("deletedAt"); - CREATE INDEX "StepRun_updatedAt_idx" ON "StepRun_new" ("updatedAt"); - CREATE INDEX "StepRun_id_tenantId_idx" ON "StepRun_new" ("id", "tenantId"); - CREATE INDEX "StepRun_jobRunId_status_idx" ON "StepRun_new" ("jobRunId", "status"); - CREATE INDEX "StepRun_jobRunId_tenantId_order_idx" ON "StepRun_new" ("jobRunId", "tenantId", "order"); - CREATE INDEX "StepRun_stepId_idx" ON "StepRun_new" ("stepId"); - CREATE INDEX "StepRun_tenantId_idx" ON "StepRun_new" ("tenantId"); - CREATE INDEX "StepRun_workerId_idx" ON "StepRun_new" ("workerId"); - CREATE INDEX "StepRun_status_tenantId_idx" ON "StepRun_new" ("status", "tenantId"); - CREATE INDEX "StepRun_id_status" ON "StepRun" ("id", "status"); - CREATE INDEX "StepRun_jobRunId_status_tenantId_idx" ON "StepRun" ("jobRunId", "status", "tenantId") WHERE (status = 'PENDING'::"StepRunStatus"); - - RAISE NOTICE 'Created indexes for "StepRun_new"'; - - RAISE NOTICE 'StepRun_new table created successfully now we try and swap the tables'; - - END IF; - - WHILE retry_count < max_retries LOOP - BEGIN - - - - - - - RAISE NOTICE 'Locking tables'; - LOCK TABLE "StepRun" IN ACCESS EXCLUSIVE MODE; - -- LOCK TABLE "StepRun_new" IN ACCESS EXCLUSIVE MODE; - - - RAISE NOTICE 'Locked tables'; - - - - - - RAISE NOTICE 'Checking for data since the last select'; - - - INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( - SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" - ); - ALTER TABLE "StepRun_volatile" - SET (autovacuum_vacuum_threshold = '1000', - autovacuum_vacuum_scale_factor = '0.01', - autovacuum_analyze_threshold = '500', - autovacuum_analyze_scale_factor = '0.01'); - - - RAISE NOTICE 'Renaming tables and copying any new data'; - - INSERT INTO "StepRun_new" - SELECT * - FROM "StepRun" - WHERE "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") - AND NOT EXISTS ( - SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" - ); - - ALTER TABLE "StepRun" RENAME TO "StepRun_old"; - ALTER TABLE "StepRun_new" RENAME TO "StepRun"; - - - - - --- Drop index "StepRun_updatedAt_idx" from table: "StepRun" - DROP INDEX IF EXISTS "StepRun_updatedAt_idx"; - - - - - - RAISE NOTICE 'Migration successful EXIT'; - COMMIT; - EXIT; -EXCEPTION - WHEN OTHERS THEN - RAISE NOTICE 'Migration failed, retrying...'; - RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; - retry_count := retry_count + 1; - RAISE NOTICE 'Attempt %', retry_count; - - if retry_count < max_retries then - -- Sleep for a bit before retrying - - PERFORM pg_sleep(sleep_interval / 1000.0); - ELSE - -- Exit the loop if max retries are reached - RAISE EXCEPTION 'Migration failed after % retries', retry_count; - END IF; - - END; - END LOOP; -END $$; - - - -DECLARE - retry_count INT := 0; - max_retries INT := 40; - sleep_interval INT := 30000; - rec RECORD; - sql_statement TEXT; - newest_record RECORD; -BEGIN - - - - LOCK TABLE "_StepRunOrder" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "StepRunResultArchive" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "LogLine" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "WorkflowTriggerScheduledRef" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "WorkflowRun" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "StreamEvent" IN ACCESS EXCLUSIVE MODE; - RAISE NOTICE 'Renamed tables now we try and create the triggers'; - - RAISE NOTICE 'Modify Workflow Run table while we have it locked'; - --- Modify "WorkflowRun" table - ALTER TABLE "WorkflowRun" ADD COLUMN "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY; - - - - FOR rec IN - SELECT - conname AS constraint_name, - conrelid::regclass AS referencing_table, - a.attname AS referencing_column, - confrelid::regclass AS referenced_table, - af.attname AS referenced_column - FROM - pg_constraint c - JOIN - pg_attribute a ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid - JOIN - pg_attribute af ON af.attnum = ANY(c.confkey) AND af.attrelid = c.confrelid - WHERE - confrelid = '"StepRun_old"'::regclass - AND contype = 'f' - LOOP - - RAISE NOTICE 'Referencing column: %, Referenced table: %, Referenced column: %', rec.referencing_column, rec.referenced_table, rec.referenced_column; - - sql_statement = 'CREATE OR REPLACE FUNCTION ' || 'StepRun' || rec.referencing_column || '_fk_trigger_function() RETURNS TRIGGER AS $function_body$ - BEGIN - IF NEW."'|| rec.referencing_column || '" IS NOT NULL THEN - IF NOT EXISTS ( - SELECT 1 - FROM "StepRun" - WHERE "' || rec.referenced_column || '" = NEW."' || rec.referencing_column || '" - ) THEN - RAISE EXCEPTION ''Foreign key violation: ' || 'StepRun' || ' with ' || rec.referenced_column || ' = % does not exist.'', NEW."' || rec.referencing_column || '"; - END IF; - END IF; - RETURN NEW; - END; - $function_body$ LANGUAGE plpgsql;'; - - RAISE NOTICE 'Executing: %', sql_statement; - - EXECUTE sql_statement; - - RAISE NOTICE 'Created trigger function for %', rec.constraint_name; - - sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_insert_trigger" - BEFORE INSERT ON ' || rec.referencing_table || ' - FOR EACH ROW - EXECUTE FUNCTION ' || 'StepRun'||rec.referencing_column|| '_fk_trigger_function();'; - RAISE NOTICE 'Executing: %', sql_statement; - EXECUTE sql_statement; - - sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_update_trigger" - BEFORE UPDATE ON ' || rec.referencing_table || ' - FOR EACH ROW - EXECUTE FUNCTION ' || 'StepRun' || rec.referencing_column|| '_fk_trigger_function();'; - RAISE NOTICE 'Executing: %', sql_statement; - - - - EXECUTE sql_statement; - - sql_statement = 'ALTER TABLE ' || rec.referencing_table || ' DROP CONSTRAINT "' || rec.constraint_name || '"'; - RAISE NOTICE 'Executing: %', sql_statement; - EXECUTE sql_statement; - - - END LOOP; - -END; --- 1. Create a new "Event" table with the desired schema (including the new identityId column) --- atlas:txmode none - - - -- 'Creating an updatedAt index that will be useful later'; create index CONCURRENTLY IF NOT EXISTS "StepRun_updatedAt_idx" on "StepRun" ("updatedAt"); -- 'Created index'; diff --git a/sql/migrations/atlas.sum b/sql/migrations/atlas.sum index 7dceebb91..22c25aa49 100644 --- a/sql/migrations/atlas.sum +++ b/sql/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:5vsqrOtNUXuZIoT3KaU05MfC9antMP9WWEqIeUZO5PU= +h1:Uxo91RtnOjhpWS25Nz39EVfrzK0pwzs1DAGBaylqJSI= 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= @@ -75,6 +75,6 @@ h1:5vsqrOtNUXuZIoT3KaU05MfC9antMP9WWEqIeUZO5PU= 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:2jle/v6mwceeuEBArHKXmZXH3ztHZi8VwcovaOAtPjY= -20241121153627_v0.52.1.sql h1:zs9qMJZE1PpP106fZ1pbiHZbrJuzlcU4wHaeJURQbzc= -20241121195232_v0.52.2.sql h1:toMEPVfz92ULyODPVBlMHJcWI+pJpLDzx86ip0oi+AY= +20241121142159_v0.52.0.sql h1:LnfNg2RE/mp8heRU/eM043kBlDnnrquRnIogiUomSYk= +20241121153627_v0.52.1.sql h1:sHprtqRs1yfoB0ZxtMpiI3lsjpm4vnibf5fJqHR9jtE= +20241121195232_v0.52.2.sql h1:XdhEqVm+tws9KLnkyiKB8xRW8xJQ+ynN6r3vmRhx9Ww= From c45386de56501992c49ff5e0e4bfaf88d76f97b7 Mon Sep 17 00:00:00 2001 From: Sean Reilly Date: Tue, 26 Nov 2024 23:10:58 -0800 Subject: [PATCH 3/3] make the migration much more robust --- Taskfile.yaml | 4 +- examples/bulk_workflows/main.go | 28 +- hack/db/atlas-apply.sh | 21 +- pkg/repository/prisma/dbsqlc/models.go | 1 - pkg/repository/prisma/dbsqlc/step_runs.sql.go | 3 +- .../prisma/dbsqlc/workflow_runs.sql.go | 41 +- pkg/repository/prisma/dbsqlc/workflows.sql.go | 3 +- .../20240115180414_init/migration.sql | 681 ---------- .../20240122014727_v0_6_0/migration.sql | 50 - .../20240126235456_v0_7_0/migration.sql | 89 -- .../20240129040510_v0_8_0/migration.sql | 79 -- .../20240202042355_v0_9_0/migration.sql | 67 - .../20240209132837_v0_10_0/migration.sql | 5 - .../20240215162148_v0_10_2/migration.sql | 12 - .../20240216133745_v0_11_0/migration.sql | 304 ----- .../20240226051822_v0_12_0/migration.sql | 5 - .../20240227181732_v0_13_0/migration.sql | 8 - .../20240228050417_v0_13_2/migration.sql | 8 - .../20240229232811_v0_14_0/migration.sql | 21 - .../20240304060408_v0_15_0/migration.sql | 19 - .../20240320215205_v0_17_0/migration.sql | 18 - .../20240321215205_v0_17_1/migration.sql | 18 - .../20240326151030_v0_18_0/migration.sql | 36 - .../20240331162333_v0_18_1/migration.sql | 11 - .../20240402034010_v0_19_0/migration.sql | 67 - .../20240424091046_v0_21_9/migration.sql | 2 - .../20240430161943_v0_22_1/migration.sql | 11 - .../20240503190030_v0_23_0/migration.sql | 2 - .../20240506194242_v0_24_0/migration.sql | 26 - .../20240507200816_v0_25_0/migration.sql | 77 -- .../20240509213608_v0_26_0/migration.sql | 56 - .../20240514192527_v0_27_0/migration.sql | 14 - .../20240514203126_v0_28_0/migration.sql | 2 - .../20240517204453_v0_28_1/migration.sql | 2 - .../20240520152239_v0_28_2/migration.sql | 2 - .../20240521205311_v0_28_3/migration.sql | 2 - .../20240531142907_v0_29_0/migration.sql | 2 - .../20240531200417_v_0_30_0/migration.sql | 6 - .../20240531200418_v0_30_1/migration.sql | 78 -- .../20240606145243_v0_31_0/migration.sql | 58 - .../20240625180539_v0_34_0/migration.sql | 138 -- .../20240626204332_v0_34_2/migration.sql | 51 - .../20240701144845_v0_35_0/migration.sql | 2 - .../20240703194644_v0_35_1/migration.sql | 35 - .../20240704211308_v0_35_2/migration.sql | 2 - .../20240712142938_v0_36_0/migration.sql | 17 - .../20240715154325_v0_37_0/migration.sql | 2 - .../20240716125848_v0_38_0/migration.sql | 2 - .../20240716143342_v0_39_0/migration.sql | 17 - .../20240726160621_v0_40_0/migration.sql | 97 -- .../20240728042304_v0_41_0/migration.sql | 5 - .../20240809130954_v0_42_0/migration.sql | 41 - .../20240815151145_v0_42_2/migration.sql | 20 - .../20240820201021_0_42_3/migration.sql | 19 - .../20240823120423_0_42_4/migration.sql | 19 - .../20240823204116_0_42_5/migration.sql | 8 - .../20240829142541_v0_43_2/migration.sql | 5 - .../20240904120320_v0_44_0/migration.sql | 53 - .../20240910201520_v0_44_5/migration.sql | 17 - .../20240911124010_v0_44_6/migration.sql | 15 - .../20240911201824_v0_44_7/migration.sql | 28 - .../20240916121446_v0_44_8/migration.sql | 27 - .../20240918162525_v0_45_0/migration.sql | 26 - .../20240923124800_v0_45_4/migration.sql | 2 - .../20240926210641_v0_47_0/migration.sql | 35 - .../20240927172926_v0_47_1/migration.sql | 65 - .../20240928144309_v0_48_0/migration.sql | 5 - .../20240930202651_v0_48_1/migration.sql | 5 - .../20241002174554_0_48_2/migration.sql | 2 - .../20241003135009_v0_49_0/migration.sql | 2 - .../20241004122152_v0_49_1/migration.sql | 2 - .../20241008124029_v0_49_2/migration.sql | 10 - .../20241011205303_0_49_3/migration.sql | 10 - .../20241014194315_v0_50_0/migration.sql | 29 - .../20241022124201_v0_50_2/migration.sql | 19 - .../20241023112223_v0_50_3/migration.sql | 5 - .../20241029122618_v0_51_0/migration.sql | 11 - .../20241030131339_tmp/migration.sql | 23 - .../20241030133040_tmp/migration.sql | 10 - .../20241030150107_tmp/migration.sql | 12 - .../20241104202817_tmp/migration.sql | 2 - .../20241107162929_v0_51_2/migration.sql | 2 - .../20241114175339_v0_51_3/migration.sql | 3 - .../20241120193249_tmp/migration.sql | 2 - .../20241120193948_tmp/migration.sql | 8 - prisma/migrations/migration_lock.toml | 3 - sql/migrations/20241121142159_v0.52.0.sql | 1158 +++++++++++++++-- sql/migrations/atlas.sum | 8 +- sql/schema/schema.sql | 9 +- 89 files changed, 1060 insertions(+), 2967 deletions(-) delete mode 100644 prisma/migrations/20240115180414_init/migration.sql delete mode 100644 prisma/migrations/20240122014727_v0_6_0/migration.sql delete mode 100644 prisma/migrations/20240126235456_v0_7_0/migration.sql delete mode 100644 prisma/migrations/20240129040510_v0_8_0/migration.sql delete mode 100644 prisma/migrations/20240202042355_v0_9_0/migration.sql delete mode 100644 prisma/migrations/20240209132837_v0_10_0/migration.sql delete mode 100644 prisma/migrations/20240215162148_v0_10_2/migration.sql delete mode 100644 prisma/migrations/20240216133745_v0_11_0/migration.sql delete mode 100644 prisma/migrations/20240226051822_v0_12_0/migration.sql delete mode 100644 prisma/migrations/20240227181732_v0_13_0/migration.sql delete mode 100644 prisma/migrations/20240228050417_v0_13_2/migration.sql delete mode 100644 prisma/migrations/20240229232811_v0_14_0/migration.sql delete mode 100644 prisma/migrations/20240304060408_v0_15_0/migration.sql delete mode 100644 prisma/migrations/20240320215205_v0_17_0/migration.sql delete mode 100644 prisma/migrations/20240321215205_v0_17_1/migration.sql delete mode 100644 prisma/migrations/20240326151030_v0_18_0/migration.sql delete mode 100644 prisma/migrations/20240331162333_v0_18_1/migration.sql delete mode 100644 prisma/migrations/20240402034010_v0_19_0/migration.sql delete mode 100644 prisma/migrations/20240424091046_v0_21_9/migration.sql delete mode 100644 prisma/migrations/20240430161943_v0_22_1/migration.sql delete mode 100644 prisma/migrations/20240503190030_v0_23_0/migration.sql delete mode 100644 prisma/migrations/20240506194242_v0_24_0/migration.sql delete mode 100644 prisma/migrations/20240507200816_v0_25_0/migration.sql delete mode 100644 prisma/migrations/20240509213608_v0_26_0/migration.sql delete mode 100644 prisma/migrations/20240514192527_v0_27_0/migration.sql delete mode 100644 prisma/migrations/20240514203126_v0_28_0/migration.sql delete mode 100644 prisma/migrations/20240517204453_v0_28_1/migration.sql delete mode 100644 prisma/migrations/20240520152239_v0_28_2/migration.sql delete mode 100644 prisma/migrations/20240521205311_v0_28_3/migration.sql delete mode 100644 prisma/migrations/20240531142907_v0_29_0/migration.sql delete mode 100644 prisma/migrations/20240531200417_v_0_30_0/migration.sql delete mode 100644 prisma/migrations/20240531200418_v0_30_1/migration.sql delete mode 100644 prisma/migrations/20240606145243_v0_31_0/migration.sql delete mode 100644 prisma/migrations/20240625180539_v0_34_0/migration.sql delete mode 100644 prisma/migrations/20240626204332_v0_34_2/migration.sql delete mode 100644 prisma/migrations/20240701144845_v0_35_0/migration.sql delete mode 100644 prisma/migrations/20240703194644_v0_35_1/migration.sql delete mode 100644 prisma/migrations/20240704211308_v0_35_2/migration.sql delete mode 100644 prisma/migrations/20240712142938_v0_36_0/migration.sql delete mode 100644 prisma/migrations/20240715154325_v0_37_0/migration.sql delete mode 100644 prisma/migrations/20240716125848_v0_38_0/migration.sql delete mode 100644 prisma/migrations/20240716143342_v0_39_0/migration.sql delete mode 100644 prisma/migrations/20240726160621_v0_40_0/migration.sql delete mode 100644 prisma/migrations/20240728042304_v0_41_0/migration.sql delete mode 100644 prisma/migrations/20240809130954_v0_42_0/migration.sql delete mode 100644 prisma/migrations/20240815151145_v0_42_2/migration.sql delete mode 100644 prisma/migrations/20240820201021_0_42_3/migration.sql delete mode 100644 prisma/migrations/20240823120423_0_42_4/migration.sql delete mode 100644 prisma/migrations/20240823204116_0_42_5/migration.sql delete mode 100644 prisma/migrations/20240829142541_v0_43_2/migration.sql delete mode 100644 prisma/migrations/20240904120320_v0_44_0/migration.sql delete mode 100644 prisma/migrations/20240910201520_v0_44_5/migration.sql delete mode 100644 prisma/migrations/20240911124010_v0_44_6/migration.sql delete mode 100644 prisma/migrations/20240911201824_v0_44_7/migration.sql delete mode 100644 prisma/migrations/20240916121446_v0_44_8/migration.sql delete mode 100644 prisma/migrations/20240918162525_v0_45_0/migration.sql delete mode 100644 prisma/migrations/20240923124800_v0_45_4/migration.sql delete mode 100644 prisma/migrations/20240926210641_v0_47_0/migration.sql delete mode 100644 prisma/migrations/20240927172926_v0_47_1/migration.sql delete mode 100644 prisma/migrations/20240928144309_v0_48_0/migration.sql delete mode 100644 prisma/migrations/20240930202651_v0_48_1/migration.sql delete mode 100644 prisma/migrations/20241002174554_0_48_2/migration.sql delete mode 100644 prisma/migrations/20241003135009_v0_49_0/migration.sql delete mode 100644 prisma/migrations/20241004122152_v0_49_1/migration.sql delete mode 100644 prisma/migrations/20241008124029_v0_49_2/migration.sql delete mode 100644 prisma/migrations/20241011205303_0_49_3/migration.sql delete mode 100644 prisma/migrations/20241014194315_v0_50_0/migration.sql delete mode 100644 prisma/migrations/20241022124201_v0_50_2/migration.sql delete mode 100644 prisma/migrations/20241023112223_v0_50_3/migration.sql delete mode 100644 prisma/migrations/20241029122618_v0_51_0/migration.sql delete mode 100644 prisma/migrations/20241030131339_tmp/migration.sql delete mode 100644 prisma/migrations/20241030133040_tmp/migration.sql delete mode 100644 prisma/migrations/20241030150107_tmp/migration.sql delete mode 100644 prisma/migrations/20241104202817_tmp/migration.sql delete mode 100644 prisma/migrations/20241107162929_v0_51_2/migration.sql delete mode 100644 prisma/migrations/20241114175339_v0_51_3/migration.sql delete mode 100644 prisma/migrations/20241120193249_tmp/migration.sql delete mode 100644 prisma/migrations/20241120193948_tmp/migration.sql delete mode 100644 prisma/migrations/migration_lock.toml diff --git a/Taskfile.yaml b/Taskfile.yaml index 150abec55..551033a0b 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -55,8 +55,8 @@ tasks: recreate-db-from-scratch: cmds: - docker compose down - - docker volume rm oss_hatchet_postgres_data - - docker volume rm oss_hatchet_rabbitmq_data + - docker volume rm oss_hatchet_postgres_data || true + - docker volume rm oss_hatchet_rabbitmq_data || true - docker compose up -d - task: setup - task: init-dev-env diff --git a/examples/bulk_workflows/main.go b/examples/bulk_workflows/main.go index 726e38a4f..cc24e0030 100644 --- a/examples/bulk_workflows/main.go +++ b/examples/bulk_workflows/main.go @@ -40,16 +40,23 @@ func main() { panic(fmt.Errorf("error creating client: %w", err)) } - _, err = registerWorkflow(c, workflowName) + w, err := registerWorkflow(c, workflowName) if err != nil { panic(fmt.Errorf("error registering workflow: %w", err)) } - quantity := 999 + cleanup, err := w.Start() + fmt.Println("Starting the worker") + + if err != nil { + panic(fmt.Errorf("error starting worker: %w", err)) + } + + quantity := 600 overallStart := time.Now() - iterations := 10 + iterations := 1000 for i := 0; i < iterations; i++ { startTime := time.Now() @@ -60,6 +67,8 @@ func main() { panic(err) } fmt.Printf("Time taken to queue %dth bulk workflow: %v\n", i, time.Since(startTime)) + + time.Sleep(1 * time.Second) } fmt.Println("Overall time taken: ", time.Since(overallStart)) fmt.Printf("That is %d workflows per second\n", int(float64(quantity*iterations)/time.Since(overallStart).Seconds())) @@ -76,18 +85,6 @@ func main() { // I want to start the wofklow worker here - w, err := registerWorkflow(c, workflowName) - if err != nil { - panic(fmt.Errorf("error creating worker: %w", err)) - } - - cleanup, err := w.Start() - fmt.Println("Starting the worker") - - if err != nil { - panic(fmt.Errorf("error starting worker: %w", err)) - } - <-ch if err := cleanup(); err != nil { @@ -102,6 +99,7 @@ func registerWorkflow(c client.Client, workflowName string) (w *worker.Worker, e worker.WithClient( c, ), + worker.WithMaxRuns(200), ) if err != nil { return nil, fmt.Errorf("error creating worker: %w", err) diff --git a/hack/db/atlas-apply.sh b/hack/db/atlas-apply.sh index bec83b0b5..18a7a554e 100644 --- a/hack/db/atlas-apply.sh +++ b/hack/db/atlas-apply.sh @@ -41,26 +41,13 @@ if [[ ! "$DATABASE_URL" =~ sslmode ]]; then fi echo "DATABASE_URL: $DATABASE_URL" -# Check for prisma migrations -MIGRATION_NAME=$(psql "$DATABASE_URL" -t -c "SELECT migration_name FROM _prisma_migrations ORDER BY started_at DESC LIMIT 1;" 2>/dev/null | xargs) -MIGRATION_NAME=$(echo $MIGRATION_NAME | cut -d'_' -f1) -echo "Migration name: $MIGRATION_NAME" +echo "Applying migrations via atlas..." -if [ $? -eq 0 ] && [ -n "$MIGRATION_NAME" ]; then - echo "Using existing prisma migration: $MIGRATION_NAME" +atlas migrate apply \ + --url "$DATABASE_URL" \ + --dir "file://sql/migrations" - atlas migrate apply \ - --url "$DATABASE_URL" \ - --baseline "$MIGRATION_NAME" \ - --dir "file://sql/migrations" -else - echo "No prisma migration found. Applying migrations via atlas..." - - atlas migrate apply \ - --url "$DATABASE_URL" \ - --dir "file://sql/migrations" -fi # if either of the above commands failed, exit with an error if [ $? -ne 0 ]; then diff --git a/pkg/repository/prisma/dbsqlc/models.go b/pkg/repository/prisma/dbsqlc/models.go index 1f429febd..100e234c0 100644 --- a/pkg/repository/prisma/dbsqlc/models.go +++ b/pkg/repository/prisma/dbsqlc/models.go @@ -1832,7 +1832,6 @@ type WorkflowRun struct { Duration pgtype.Int8 `json:"duration"` Priority pgtype.Int4 `json:"priority"` InsertOrder pgtype.Int4 `json:"insertOrder"` - IdentityId pgtype.Int8 `json:"identityId"` } type WorkflowRunDedupe struct { diff --git a/pkg/repository/prisma/dbsqlc/step_runs.sql.go b/pkg/repository/prisma/dbsqlc/step_runs.sql.go index a094f0b99..3c1959837 100644 --- a/pkg/repository/prisma/dbsqlc/step_runs.sql.go +++ b/pkg/repository/prisma/dbsqlc/step_runs.sql.go @@ -2599,7 +2599,7 @@ SET "error" = NULL WHERE "id" = $1::uuid -RETURNING "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder", "identityId" +RETURNING "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder" ` func (q *Queries) ReplayStepRunResetWorkflowRun(ctx context.Context, db DBTX, workflowrunid pgtype.UUID) (*WorkflowRun, error) { @@ -2626,7 +2626,6 @@ func (q *Queries) ReplayStepRunResetWorkflowRun(ctx context.Context, db DBTX, wo &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ) return &i, err } diff --git a/pkg/repository/prisma/dbsqlc/workflow_runs.sql.go b/pkg/repository/prisma/dbsqlc/workflow_runs.sql.go index 9d64689be..0a651671a 100644 --- a/pkg/repository/prisma/dbsqlc/workflow_runs.sql.go +++ b/pkg/repository/prisma/dbsqlc/workflow_runs.sql.go @@ -845,7 +845,7 @@ INSERT INTO "WorkflowRun" ( $8::uuid, $9::jsonb, $10::int -) RETURNING "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder", "identityId" +) RETURNING "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder" ` type CreateWorkflowRunParams struct { @@ -896,7 +896,6 @@ func (q *Queries) CreateWorkflowRun(ctx context.Context, db DBTX, arg CreateWork &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ) return &i, err } @@ -1110,7 +1109,7 @@ func (q *Queries) DeleteScheduledWorkflow(ctx context.Context, db DBTX, schedule const getChildWorkflowRun = `-- name: GetChildWorkflowRun :one SELECT - "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder", "identityId" + "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder" FROM "WorkflowRun" WHERE @@ -1160,14 +1159,13 @@ func (q *Queries) GetChildWorkflowRun(ctx context.Context, db DBTX, arg GetChild &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ) return &i, err } const getChildWorkflowRunsByIndex = `-- name: GetChildWorkflowRunsByIndex :many SELECT - wr."createdAt", wr."updatedAt", wr."deletedAt", wr."tenantId", wr."workflowVersionId", wr.status, wr.error, wr."startedAt", wr."finishedAt", wr."concurrencyGroupId", wr."displayName", wr.id, wr."childIndex", wr."childKey", wr."parentId", wr."parentStepRunId", wr."additionalMetadata", wr.duration, wr.priority, wr."insertOrder", wr."identityId" + wr."createdAt", wr."updatedAt", wr."deletedAt", wr."tenantId", wr."workflowVersionId", wr.status, wr.error, wr."startedAt", wr."finishedAt", wr."concurrencyGroupId", wr."displayName", wr.id, wr."childIndex", wr."childKey", wr."parentId", wr."parentStepRunId", wr."additionalMetadata", wr.duration, wr.priority, wr."insertOrder" FROM "WorkflowRun" wr WHERE @@ -1216,7 +1214,6 @@ func (q *Queries) GetChildWorkflowRunsByIndex(ctx context.Context, db DBTX, arg &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ); err != nil { return nil, err } @@ -1230,7 +1227,7 @@ func (q *Queries) GetChildWorkflowRunsByIndex(ctx context.Context, db DBTX, arg const getChildWorkflowRunsByKey = `-- name: GetChildWorkflowRunsByKey :many SELECT - wr."createdAt", wr."updatedAt", wr."deletedAt", wr."tenantId", wr."workflowVersionId", wr.status, wr.error, wr."startedAt", wr."finishedAt", wr."concurrencyGroupId", wr."displayName", wr.id, wr."childIndex", wr."childKey", wr."parentId", wr."parentStepRunId", wr."additionalMetadata", wr.duration, wr.priority, wr."insertOrder", wr."identityId" + wr."createdAt", wr."updatedAt", wr."deletedAt", wr."tenantId", wr."workflowVersionId", wr.status, wr.error, wr."startedAt", wr."finishedAt", wr."concurrencyGroupId", wr."displayName", wr.id, wr."childIndex", wr."childKey", wr."parentId", wr."parentStepRunId", wr."additionalMetadata", wr.duration, wr.priority, wr."insertOrder" FROM "WorkflowRun" wr WHERE @@ -1279,7 +1276,6 @@ func (q *Queries) GetChildWorkflowRunsByKey(ctx context.Context, db DBTX, arg Ge &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ); err != nil { return nil, err } @@ -1605,7 +1601,7 @@ func (q *Queries) GetStepsForWorkflowVersion(ctx context.Context, db DBTX, workf const getWorkflowRun = `-- name: GetWorkflowRun :many SELECT - runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", runs."identityId", + runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", runtriggers.id, runtriggers."createdAt", runtriggers."updatedAt", runtriggers."deletedAt", runtriggers."tenantId", runtriggers."eventId", runtriggers."cronParentId", runtriggers."cronSchedule", runtriggers."scheduledId", runtriggers.input, runtriggers."parentId", runtriggers."cronName", runtriggers."identityId", workflowversion.id, workflowversion."createdAt", workflowversion."updatedAt", workflowversion."deletedAt", workflowversion.version, workflowversion."order", workflowversion."workflowId", workflowversion.checksum, workflowversion."scheduleTimeout", workflowversion."onFailureJobId", workflowversion.sticky, workflowversion.kind, workflowversion."defaultPriority", workflow."name" as "workflowName", @@ -1682,7 +1678,6 @@ func (q *Queries) GetWorkflowRun(ctx context.Context, db DBTX, arg GetWorkflowRu &i.WorkflowRun.Duration, &i.WorkflowRun.Priority, &i.WorkflowRun.InsertOrder, - &i.WorkflowRun.IdentityId, &i.WorkflowRunTriggeredBy.ID, &i.WorkflowRunTriggeredBy.CreatedAt, &i.WorkflowRunTriggeredBy.UpdatedAt, @@ -1756,7 +1751,7 @@ func (q *Queries) GetWorkflowRunAdditionalMeta(ctx context.Context, db DBTX, arg const getWorkflowRunById = `-- name: GetWorkflowRunById :one SELECT - r."createdAt", r."updatedAt", r."deletedAt", r."tenantId", r."workflowVersionId", r.status, r.error, r."startedAt", r."finishedAt", r."concurrencyGroupId", r."displayName", r.id, r."childIndex", r."childKey", r."parentId", r."parentStepRunId", r."additionalMetadata", r.duration, r.priority, r."insertOrder", r."identityId", + r."createdAt", r."updatedAt", r."deletedAt", r."tenantId", r."workflowVersionId", r.status, r.error, r."startedAt", r."finishedAt", r."concurrencyGroupId", r."displayName", r.id, r."childIndex", r."childKey", r."parentId", r."parentStepRunId", r."additionalMetadata", r.duration, r.priority, r."insertOrder", wv.id, wv."createdAt", wv."updatedAt", wv."deletedAt", wv.version, wv."order", wv."workflowId", wv.checksum, wv."scheduleTimeout", wv."onFailureJobId", wv.sticky, wv.kind, wv."defaultPriority", w.id, w."createdAt", w."updatedAt", w."deletedAt", w."tenantId", w.name, w.description, w."isPaused", tb.id, tb."createdAt", tb."updatedAt", tb."deletedAt", tb."tenantId", tb."eventId", tb."cronParentId", tb."cronSchedule", tb."scheduledId", tb.input, tb."parentId", tb."cronName", tb."identityId" @@ -1800,7 +1795,6 @@ type GetWorkflowRunByIdRow struct { Duration pgtype.Int8 `json:"duration"` Priority pgtype.Int4 `json:"priority"` InsertOrder pgtype.Int4 `json:"insertOrder"` - IdentityId pgtype.Int8 `json:"identityId"` WorkflowVersion WorkflowVersion `json:"workflow_version"` Workflow Workflow `json:"workflow"` WorkflowRunTriggeredBy WorkflowRunTriggeredBy `json:"workflow_run_triggered_by"` @@ -1830,7 +1824,6 @@ func (q *Queries) GetWorkflowRunById(ctx context.Context, db DBTX, arg GetWorkfl &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, &i.WorkflowVersion.ID, &i.WorkflowVersion.CreatedAt, &i.WorkflowVersion.UpdatedAt, @@ -1871,7 +1864,7 @@ func (q *Queries) GetWorkflowRunById(ctx context.Context, db DBTX, arg GetWorkfl const getWorkflowRunByIds = `-- name: GetWorkflowRunByIds :many SELECT - r."createdAt", r."updatedAt", r."deletedAt", r."tenantId", r."workflowVersionId", r.status, r.error, r."startedAt", r."finishedAt", r."concurrencyGroupId", r."displayName", r.id, r."childIndex", r."childKey", r."parentId", r."parentStepRunId", r."additionalMetadata", r.duration, r.priority, r."insertOrder", r."identityId", + r."createdAt", r."updatedAt", r."deletedAt", r."tenantId", r."workflowVersionId", r.status, r.error, r."startedAt", r."finishedAt", r."concurrencyGroupId", r."displayName", r.id, r."childIndex", r."childKey", r."parentId", r."parentStepRunId", r."additionalMetadata", r.duration, r.priority, r."insertOrder", wv.id, wv."createdAt", wv."updatedAt", wv."deletedAt", wv.version, wv."order", wv."workflowId", wv.checksum, wv."scheduleTimeout", wv."onFailureJobId", wv.sticky, wv.kind, wv."defaultPriority", w.id, w."createdAt", w."updatedAt", w."deletedAt", w."tenantId", w.name, w.description, w."isPaused", tb.id, tb."createdAt", tb."updatedAt", tb."deletedAt", tb."tenantId", tb."eventId", tb."cronParentId", tb."cronSchedule", tb."scheduledId", tb.input, tb."parentId", tb."cronName", tb."identityId" @@ -1915,7 +1908,6 @@ type GetWorkflowRunByIdsRow struct { Duration pgtype.Int8 `json:"duration"` Priority pgtype.Int4 `json:"priority"` InsertOrder pgtype.Int4 `json:"insertOrder"` - IdentityId pgtype.Int8 `json:"identityId"` WorkflowVersion WorkflowVersion `json:"workflow_version"` Workflow Workflow `json:"workflow"` WorkflowRunTriggeredBy WorkflowRunTriggeredBy `json:"workflow_run_triggered_by"` @@ -1951,7 +1943,6 @@ func (q *Queries) GetWorkflowRunByIds(ctx context.Context, db DBTX, arg GetWorkf &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, &i.WorkflowVersion.ID, &i.WorkflowVersion.CreatedAt, &i.WorkflowVersion.UpdatedAt, @@ -2079,7 +2070,7 @@ func (q *Queries) GetWorkflowRunTrigger(ctx context.Context, db DBTX, arg GetWor } const getWorkflowRunsInsertedInThisTxn = `-- name: GetWorkflowRunsInsertedInThisTxn :many -SELECT "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder", "identityId" FROM "WorkflowRun" +SELECT "createdAt", "updatedAt", "deletedAt", "tenantId", "workflowVersionId", status, error, "startedAt", "finishedAt", "concurrencyGroupId", "displayName", id, "childIndex", "childKey", "parentId", "parentStepRunId", "additionalMetadata", duration, priority, "insertOrder" FROM "WorkflowRun" WHERE xmin::text = (txid_current() % (2^32)::bigint)::text AND ("createdAt" = CURRENT_TIMESTAMP::timestamp(3)) ORDER BY "insertOrder" ASC @@ -2115,7 +2106,6 @@ func (q *Queries) GetWorkflowRunsInsertedInThisTxn(ctx context.Context, db DBTX) &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ); err != nil { return nil, err } @@ -2478,7 +2468,7 @@ func (q *Queries) ListWorkflowRunEventsByWorkflowRunId(ctx context.Context, db D const listWorkflowRuns = `-- name: ListWorkflowRuns :many SELECT - runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", runs."identityId", + runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", workflow.id, workflow."createdAt", workflow."updatedAt", workflow."deletedAt", workflow."tenantId", workflow.name, workflow.description, workflow."isPaused", runtriggers.id, runtriggers."createdAt", runtriggers."updatedAt", runtriggers."deletedAt", runtriggers."tenantId", runtriggers."eventId", runtriggers."cronParentId", runtriggers."cronSchedule", runtriggers."scheduledId", runtriggers.input, runtriggers."parentId", runtriggers."cronName", runtriggers."identityId", workflowversion.id, workflowversion."createdAt", workflowversion."updatedAt", workflowversion."deletedAt", workflowversion.version, workflowversion."order", workflowversion."workflowId", workflowversion.checksum, workflowversion."scheduleTimeout", workflowversion."onFailureJobId", workflowversion.sticky, workflowversion.kind, workflowversion."defaultPriority", @@ -2660,7 +2650,6 @@ func (q *Queries) ListWorkflowRuns(ctx context.Context, db DBTX, arg ListWorkflo &i.WorkflowRun.Duration, &i.WorkflowRun.Priority, &i.WorkflowRun.InsertOrder, - &i.WorkflowRun.IdentityId, &i.Workflow.ID, &i.Workflow.CreatedAt, &i.Workflow.UpdatedAt, @@ -2771,7 +2760,7 @@ WHERE "WorkflowRun".id = eligible_runs.id AND "WorkflowRun"."status" = 'QUEUED' RETURNING - "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder", "WorkflowRun"."identityId" + "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder" ` type PopWorkflowRunsRoundRobinParams struct { @@ -2810,7 +2799,6 @@ func (q *Queries) PopWorkflowRunsRoundRobin(ctx context.Context, db DBTX, arg Po &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ); err != nil { return nil, err } @@ -3072,7 +3060,7 @@ SET WHERE "tenantId" = $5::uuid AND "id" = ANY($6::uuid[]) -RETURNING "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder", "WorkflowRun"."identityId" +RETURNING "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder" ` type UpdateManyWorkflowRunParams struct { @@ -3121,7 +3109,6 @@ func (q *Queries) UpdateManyWorkflowRun(ctx context.Context, db DBTX, arg Update &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ); err != nil { return nil, err } @@ -3168,7 +3155,7 @@ SET WHERE "id" = $5::uuid AND "tenantId" = $6::uuid -RETURNING "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder", "WorkflowRun"."identityId" +RETURNING "WorkflowRun"."createdAt", "WorkflowRun"."updatedAt", "WorkflowRun"."deletedAt", "WorkflowRun"."tenantId", "WorkflowRun"."workflowVersionId", "WorkflowRun".status, "WorkflowRun".error, "WorkflowRun"."startedAt", "WorkflowRun"."finishedAt", "WorkflowRun"."concurrencyGroupId", "WorkflowRun"."displayName", "WorkflowRun".id, "WorkflowRun"."childIndex", "WorkflowRun"."childKey", "WorkflowRun"."parentId", "WorkflowRun"."parentStepRunId", "WorkflowRun"."additionalMetadata", "WorkflowRun".duration, "WorkflowRun".priority, "WorkflowRun"."insertOrder" ` type UpdateWorkflowRunParams struct { @@ -3211,7 +3198,6 @@ func (q *Queries) UpdateWorkflowRun(ctx context.Context, db DBTX, arg UpdateWork &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ) return &i, err } @@ -3292,7 +3278,7 @@ FROM WHERE workflowRun."id" = groupKeyRun."workflowRunId" AND workflowRun."tenantId" = $1::uuid -RETURNING workflowrun."createdAt", workflowrun."updatedAt", workflowrun."deletedAt", workflowrun."tenantId", workflowrun."workflowVersionId", workflowrun.status, workflowrun.error, workflowrun."startedAt", workflowrun."finishedAt", workflowrun."concurrencyGroupId", workflowrun."displayName", workflowrun.id, workflowrun."childIndex", workflowrun."childKey", workflowrun."parentId", workflowrun."parentStepRunId", workflowrun."additionalMetadata", workflowrun.duration, workflowrun.priority, workflowrun."insertOrder", workflowrun."identityId" +RETURNING workflowrun."createdAt", workflowrun."updatedAt", workflowrun."deletedAt", workflowrun."tenantId", workflowrun."workflowVersionId", workflowrun.status, workflowrun.error, workflowrun."startedAt", workflowrun."finishedAt", workflowrun."concurrencyGroupId", workflowrun."displayName", workflowrun.id, workflowrun."childIndex", workflowrun."childKey", workflowrun."parentId", workflowrun."parentStepRunId", workflowrun."additionalMetadata", workflowrun.duration, workflowrun.priority, workflowrun."insertOrder" ` type UpdateWorkflowRunGroupKeyFromRunParams struct { @@ -3324,7 +3310,6 @@ func (q *Queries) UpdateWorkflowRunGroupKeyFromRun(ctx context.Context, db DBTX, &i.Duration, &i.Priority, &i.InsertOrder, - &i.IdentityId, ) return &i, err } diff --git a/pkg/repository/prisma/dbsqlc/workflows.sql.go b/pkg/repository/prisma/dbsqlc/workflows.sql.go index eba3d4ec5..8f4b3accd 100644 --- a/pkg/repository/prisma/dbsqlc/workflows.sql.go +++ b/pkg/repository/prisma/dbsqlc/workflows.sql.go @@ -1863,7 +1863,7 @@ func (q *Queries) ListWorkflowsForEvent(ctx context.Context, db DBTX, arg ListWo const listWorkflowsLatestRuns = `-- name: ListWorkflowsLatestRuns :many SELECT - DISTINCT ON (workflow."id") runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", runs."identityId", workflow."id" as "workflowId" + DISTINCT ON (workflow."id") runs."createdAt", runs."updatedAt", runs."deletedAt", runs."tenantId", runs."workflowVersionId", runs.status, runs.error, runs."startedAt", runs."finishedAt", runs."concurrencyGroupId", runs."displayName", runs.id, runs."childIndex", runs."childKey", runs."parentId", runs."parentStepRunId", runs."additionalMetadata", runs.duration, runs.priority, runs."insertOrder", workflow."id" as "workflowId" FROM "WorkflowRun" as runs LEFT JOIN @@ -1945,7 +1945,6 @@ func (q *Queries) ListWorkflowsLatestRuns(ctx context.Context, db DBTX, arg List &i.WorkflowRun.Duration, &i.WorkflowRun.Priority, &i.WorkflowRun.InsertOrder, - &i.WorkflowRun.IdentityId, &i.WorkflowId, ); err != nil { return nil, err diff --git a/prisma/migrations/20240115180414_init/migration.sql b/prisma/migrations/20240115180414_init/migration.sql deleted file mode 100644 index 5dc7bbd23..000000000 --- a/prisma/migrations/20240115180414_init/migration.sql +++ /dev/null @@ -1,681 +0,0 @@ --- CreateEnum -CREATE TYPE "TenantMemberRole" AS ENUM ('OWNER', 'ADMIN', 'MEMBER'); - --- CreateEnum -CREATE TYPE "WorkflowRunStatus" AS ENUM ('PENDING', 'RUNNING', 'SUCCEEDED', 'FAILED'); - --- CreateEnum -CREATE TYPE "JobRunStatus" AS ENUM ('PENDING', 'RUNNING', 'SUCCEEDED', 'FAILED', 'CANCELLED'); - --- CreateEnum -CREATE TYPE "StepRunStatus" AS ENUM ('PENDING', 'PENDING_ASSIGNMENT', 'ASSIGNED', 'RUNNING', 'SUCCEEDED', 'FAILED', 'CANCELLED'); - --- CreateEnum -CREATE TYPE "WorkerStatus" AS ENUM ('ACTIVE', 'INACTIVE'); - --- CreateTable -CREATE TABLE "User" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "email" TEXT NOT NULL, - "emailVerified" BOOLEAN NOT NULL DEFAULT false, - "name" TEXT, - - CONSTRAINT "User_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "UserPassword" ( - "hash" TEXT NOT NULL, - "userId" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "UserSession" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "userId" UUID, - "data" JSONB, - "expiresAt" TIMESTAMP(3) NOT NULL, - - CONSTRAINT "UserSession_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Tenant" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "name" TEXT NOT NULL, - "slug" TEXT NOT NULL, - - CONSTRAINT "Tenant_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TenantMember" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "userId" UUID NOT NULL, - "role" "TenantMemberRole" NOT NULL, - - CONSTRAINT "TenantMember_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Event" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "key" TEXT NOT NULL, - "tenantId" UUID NOT NULL, - "replayedFromId" UUID, - "data" JSONB, - - CONSTRAINT "Event_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowTag" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "name" TEXT NOT NULL, - "color" TEXT NOT NULL DEFAULT '#93C5FD', - - CONSTRAINT "WorkflowTag_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Workflow" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "name" TEXT NOT NULL, - "description" TEXT, - - CONSTRAINT "Workflow_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowVersion" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "version" TEXT NOT NULL, - "order" SMALLSERIAL NOT NULL, - "workflowId" UUID NOT NULL, - - CONSTRAINT "WorkflowVersion_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowTriggers" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "workflowVersionId" UUID NOT NULL, - "tenantId" UUID NOT NULL, - - CONSTRAINT "WorkflowTriggers_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowTriggerEventRef" ( - "parentId" UUID NOT NULL, - "eventKey" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "WorkflowTriggerCronRef" ( - "parentId" UUID NOT NULL, - "cron" TEXT NOT NULL, - "tickerId" UUID -); - --- CreateTable -CREATE TABLE "WorkflowTriggerScheduledRef" ( - "id" UUID NOT NULL, - "parentId" UUID NOT NULL, - "triggerAt" TIMESTAMP(3) NOT NULL, - "tickerId" UUID, - "input" JSONB, - - CONSTRAINT "WorkflowTriggerScheduledRef_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Job" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "workflowVersionId" UUID NOT NULL, - "name" TEXT NOT NULL, - "description" TEXT, - "timeout" TEXT, - - CONSTRAINT "Job_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Action" ( - "id" TEXT NOT NULL, - "description" TEXT, - "tenantId" UUID NOT NULL, - - CONSTRAINT "Action_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Step" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "readableId" TEXT, - "tenantId" UUID NOT NULL, - "jobId" UUID NOT NULL, - "actionId" TEXT NOT NULL, - "timeout" TEXT, - - CONSTRAINT "Step_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowRun" ( - "id" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "workflowVersionId" UUID NOT NULL, - "status" "WorkflowRunStatus" NOT NULL DEFAULT 'PENDING', - "error" TEXT, - "startedAt" TIMESTAMP(3), - "finishedAt" TIMESTAMP(3), - - CONSTRAINT "WorkflowRun_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowRunTriggeredBy" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "parentId" TEXT NOT NULL, - "eventId" UUID, - "cronParentId" UUID, - "cronSchedule" TEXT, - "scheduledId" UUID, - - CONSTRAINT "WorkflowRunTriggeredBy_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "JobRun" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "workflowRunId" TEXT NOT NULL, - "jobId" UUID NOT NULL, - "tickerId" UUID, - "status" "JobRunStatus" NOT NULL DEFAULT 'PENDING', - "result" JSONB, - "startedAt" TIMESTAMP(3), - "finishedAt" TIMESTAMP(3), - "timeoutAt" TIMESTAMP(3), - "cancelledAt" TIMESTAMP(3), - "cancelledReason" TEXT, - "cancelledError" TEXT, - - CONSTRAINT "JobRun_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "JobRunLookupData" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "jobRunId" UUID NOT NULL, - "tenantId" UUID NOT NULL, - "data" JSONB, - - CONSTRAINT "JobRunLookupData_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "StepRun" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "jobRunId" UUID NOT NULL, - "stepId" UUID NOT NULL, - "order" SMALLSERIAL NOT NULL, - "workerId" UUID, - "tickerId" UUID, - "status" "StepRunStatus" NOT NULL DEFAULT 'PENDING', - "input" JSONB, - "output" JSONB, - "requeueAfter" TIMESTAMP(3), - "scheduleTimeoutAt" TIMESTAMP(3), - "error" TEXT, - "startedAt" TIMESTAMP(3), - "finishedAt" TIMESTAMP(3), - "timeoutAt" TIMESTAMP(3), - "cancelledAt" TIMESTAMP(3), - "cancelledReason" TEXT, - "cancelledError" TEXT, - - CONSTRAINT "StepRun_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Dispatcher" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "lastHeartbeatAt" TIMESTAMP(3), - "isActive" BOOLEAN NOT NULL DEFAULT true, - - CONSTRAINT "Dispatcher_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Ticker" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastHeartbeatAt" TIMESTAMP(3), - "isActive" BOOLEAN NOT NULL DEFAULT true, - - CONSTRAINT "Ticker_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Worker" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "lastHeartbeatAt" TIMESTAMP(3), - "name" TEXT NOT NULL, - "status" "WorkerStatus" NOT NULL DEFAULT 'ACTIVE', - "dispatcherId" UUID NOT NULL, - - CONSTRAINT "Worker_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "Service" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "name" TEXT NOT NULL, - "description" TEXT, - "tenantId" UUID NOT NULL, - - CONSTRAINT "Service_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "_WorkflowToWorkflowTag" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_ActionToWorker" ( - "A" TEXT NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_StepOrder" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_StepRunOrder" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_ServiceToWorker" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateIndex -CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); - --- CreateIndex -CREATE UNIQUE INDEX "UserPassword_userId_key" ON "UserPassword"("userId"); - --- CreateIndex -CREATE UNIQUE INDEX "UserSession_id_key" ON "UserSession"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Tenant_id_key" ON "Tenant"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Tenant_slug_key" ON "Tenant"("slug"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantMember_id_key" ON "TenantMember"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantMember_tenantId_userId_key" ON "TenantMember"("tenantId", "userId"); - --- CreateIndex -CREATE UNIQUE INDEX "Event_id_key" ON "Event"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTag_id_key" ON "WorkflowTag"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTag_tenantId_name_key" ON "WorkflowTag"("tenantId", "name"); - --- CreateIndex -CREATE UNIQUE INDEX "Workflow_id_key" ON "Workflow"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Workflow_tenantId_name_key" ON "Workflow"("tenantId", "name"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowVersion_id_key" ON "WorkflowVersion"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowVersion_workflowId_version_key" ON "WorkflowVersion"("workflowId", "version"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggers_id_key" ON "WorkflowTriggers"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggers_workflowVersionId_key" ON "WorkflowTriggers"("workflowVersionId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerEventRef_parentId_eventKey_key" ON "WorkflowTriggerEventRef"("parentId", "eventKey"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerCronRef_parentId_cron_key" ON "WorkflowTriggerCronRef"("parentId", "cron"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerScheduledRef_id_key" ON "WorkflowTriggerScheduledRef"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Job_id_key" ON "Job"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Job_workflowVersionId_name_key" ON "Job"("workflowVersionId", "name"); - --- CreateIndex -CREATE UNIQUE INDEX "Action_tenantId_id_key" ON "Action"("tenantId", "id"); - --- CreateIndex -CREATE UNIQUE INDEX "Step_id_key" ON "Step"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Step_jobId_readableId_key" ON "Step"("jobId", "readableId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRun_tenantId_id_key" ON "WorkflowRun"("tenantId", "id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunTriggeredBy_id_key" ON "WorkflowRunTriggeredBy"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunTriggeredBy_parentId_key" ON "WorkflowRunTriggeredBy"("parentId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunTriggeredBy_scheduledId_key" ON "WorkflowRunTriggeredBy"("scheduledId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunTriggeredBy_tenantId_parentId_key" ON "WorkflowRunTriggeredBy"("tenantId", "parentId"); - --- CreateIndex -CREATE UNIQUE INDEX "JobRun_id_key" ON "JobRun"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "JobRunLookupData_id_key" ON "JobRunLookupData"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "JobRunLookupData_jobRunId_key" ON "JobRunLookupData"("jobRunId"); - --- CreateIndex -CREATE UNIQUE INDEX "JobRunLookupData_jobRunId_tenantId_key" ON "JobRunLookupData"("jobRunId", "tenantId"); - --- CreateIndex -CREATE UNIQUE INDEX "StepRun_id_key" ON "StepRun"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Dispatcher_id_key" ON "Dispatcher"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Ticker_id_key" ON "Ticker"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Worker_id_key" ON "Worker"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Service_id_key" ON "Service"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Service_tenantId_name_key" ON "Service"("tenantId", "name"); - --- CreateIndex -CREATE UNIQUE INDEX "_WorkflowToWorkflowTag_AB_unique" ON "_WorkflowToWorkflowTag"("A", "B"); - --- CreateIndex -CREATE INDEX "_WorkflowToWorkflowTag_B_index" ON "_WorkflowToWorkflowTag"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_ActionToWorker_AB_unique" ON "_ActionToWorker"("A", "B"); - --- CreateIndex -CREATE INDEX "_ActionToWorker_B_index" ON "_ActionToWorker"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_StepOrder_AB_unique" ON "_StepOrder"("A", "B"); - --- CreateIndex -CREATE INDEX "_StepOrder_B_index" ON "_StepOrder"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_StepRunOrder_AB_unique" ON "_StepRunOrder"("A", "B"); - --- CreateIndex -CREATE INDEX "_StepRunOrder_B_index" ON "_StepRunOrder"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_ServiceToWorker_AB_unique" ON "_ServiceToWorker"("A", "B"); - --- CreateIndex -CREATE INDEX "_ServiceToWorker_B_index" ON "_ServiceToWorker"("B"); - --- AddForeignKey -ALTER TABLE "UserPassword" ADD CONSTRAINT "UserPassword_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "UserSession" ADD CONSTRAINT "UserSession_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantMember" ADD CONSTRAINT "TenantMember_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantMember" ADD CONSTRAINT "TenantMember_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Event" ADD CONSTRAINT "Event_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Event" ADD CONSTRAINT "Event_replayedFromId_fkey" FOREIGN KEY ("replayedFromId") REFERENCES "Event"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTag" ADD CONSTRAINT "WorkflowTag_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Workflow" ADD CONSTRAINT "Workflow_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowVersion" ADD CONSTRAINT "WorkflowVersion_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "Workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggers" ADD CONSTRAINT "WorkflowTriggers_workflowVersionId_fkey" FOREIGN KEY ("workflowVersionId") REFERENCES "WorkflowVersion"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggers" ADD CONSTRAINT "WorkflowTriggers_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerEventRef" ADD CONSTRAINT "WorkflowTriggerEventRef_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowTriggers"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerCronRef" ADD CONSTRAINT "WorkflowTriggerCronRef_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowTriggers"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerCronRef" ADD CONSTRAINT "WorkflowTriggerCronRef_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerScheduledRef" ADD CONSTRAINT "WorkflowTriggerScheduledRef_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowVersion"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerScheduledRef" ADD CONSTRAINT "WorkflowTriggerScheduledRef_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Job" ADD CONSTRAINT "Job_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Job" ADD CONSTRAINT "Job_workflowVersionId_fkey" FOREIGN KEY ("workflowVersionId") REFERENCES "WorkflowVersion"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Action" ADD CONSTRAINT "Action_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Step" ADD CONSTRAINT "Step_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Step" ADD CONSTRAINT "Step_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "Job"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Step" ADD CONSTRAINT "Step_actionId_tenantId_fkey" FOREIGN KEY ("actionId", "tenantId") REFERENCES "Action"("id", "tenantId") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRun" ADD CONSTRAINT "WorkflowRun_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRun" ADD CONSTRAINT "WorkflowRun_workflowVersionId_fkey" FOREIGN KEY ("workflowVersionId") REFERENCES "WorkflowVersion"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_cronParentId_cronSchedule_fkey" FOREIGN KEY ("cronParentId", "cronSchedule") REFERENCES "WorkflowTriggerCronRef"("parentId", "cron") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_scheduledId_fkey" FOREIGN KEY ("scheduledId") REFERENCES "WorkflowTriggerScheduledRef"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRun" ADD CONSTRAINT "JobRun_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRun" ADD CONSTRAINT "JobRun_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRun" ADD CONSTRAINT "JobRun_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "Job"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRun" ADD CONSTRAINT "JobRun_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRunLookupData" ADD CONSTRAINT "JobRunLookupData_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRunLookupData" ADD CONSTRAINT "JobRunLookupData_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRun" ADD CONSTRAINT "StepRun_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRun" ADD CONSTRAINT "StepRun_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRun" ADD CONSTRAINT "StepRun_stepId_fkey" FOREIGN KEY ("stepId") REFERENCES "Step"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRun" ADD CONSTRAINT "StepRun_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRun" ADD CONSTRAINT "StepRun_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Worker" ADD CONSTRAINT "Worker_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Worker" ADD CONSTRAINT "Worker_dispatcherId_fkey" FOREIGN KEY ("dispatcherId") REFERENCES "Dispatcher"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Service" ADD CONSTRAINT "Service_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_WorkflowToWorkflowTag" ADD CONSTRAINT "_WorkflowToWorkflowTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_WorkflowToWorkflowTag" ADD CONSTRAINT "_WorkflowToWorkflowTag_B_fkey" FOREIGN KEY ("B") REFERENCES "WorkflowTag"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_ActionToWorker" ADD CONSTRAINT "_ActionToWorker_A_fkey" FOREIGN KEY ("A") REFERENCES "Action"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_ActionToWorker" ADD CONSTRAINT "_ActionToWorker_B_fkey" FOREIGN KEY ("B") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_StepOrder" ADD CONSTRAINT "_StepOrder_A_fkey" FOREIGN KEY ("A") REFERENCES "Step"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_StepOrder" ADD CONSTRAINT "_StepOrder_B_fkey" FOREIGN KEY ("B") REFERENCES "Step"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_StepRunOrder" ADD CONSTRAINT "_StepRunOrder_A_fkey" FOREIGN KEY ("A") REFERENCES "StepRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_StepRunOrder" ADD CONSTRAINT "_StepRunOrder_B_fkey" FOREIGN KEY ("B") REFERENCES "StepRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_ServiceToWorker" ADD CONSTRAINT "_ServiceToWorker_A_fkey" FOREIGN KEY ("A") REFERENCES "Service"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_ServiceToWorker" ADD CONSTRAINT "_ServiceToWorker_B_fkey" FOREIGN KEY ("B") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240122014727_v0_6_0/migration.sql b/prisma/migrations/20240122014727_v0_6_0/migration.sql deleted file mode 100644 index 9ae9238df..000000000 --- a/prisma/migrations/20240122014727_v0_6_0/migration.sql +++ /dev/null @@ -1,50 +0,0 @@ --- CreateEnum -CREATE TYPE "InviteLinkStatus" AS ENUM ('PENDING', 'ACCEPTED', 'REJECTED'); - --- CreateTable -CREATE TABLE "UserOAuth" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "userId" UUID NOT NULL, - "provider" TEXT NOT NULL, - "providerUserId" TEXT NOT NULL, - "accessToken" TEXT NOT NULL, - "refreshToken" TEXT, - "expiresAt" TIMESTAMP(3), - - CONSTRAINT "UserOAuth_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TenantInviteLink" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "inviterEmail" TEXT NOT NULL, - "inviteeEmail" TEXT NOT NULL, - "expires" TIMESTAMP(3) NOT NULL, - "status" "InviteLinkStatus" NOT NULL DEFAULT 'PENDING', - "role" "TenantMemberRole" NOT NULL DEFAULT 'OWNER', - - CONSTRAINT "TenantInviteLink_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "UserOAuth_id_key" ON "UserOAuth"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "UserOAuth_userId_key" ON "UserOAuth"("userId"); - --- CreateIndex -CREATE UNIQUE INDEX "UserOAuth_userId_provider_key" ON "UserOAuth"("userId", "provider"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantInviteLink_id_key" ON "TenantInviteLink"("id"); - --- AddForeignKey -ALTER TABLE "UserOAuth" ADD CONSTRAINT "UserOAuth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantInviteLink" ADD CONSTRAINT "TenantInviteLink_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240126235456_v0_7_0/migration.sql b/prisma/migrations/20240126235456_v0_7_0/migration.sql deleted file mode 100644 index c908638b2..000000000 --- a/prisma/migrations/20240126235456_v0_7_0/migration.sql +++ /dev/null @@ -1,89 +0,0 @@ -/* - Warnings: - - - The primary key for the `Action` table will be changed. If it partially fails, the table could be left without primary key constraint. - - The `refreshToken` column on the `UserOAuth` table would be dropped and recreated. This will lead to data loss if there is data in the column. - - A unique constraint covering the columns `[id]` on the table `Action` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[tenantId,actionId]` on the table `Action` will be added. If there are existing duplicate values, this will fail. - - Added the required column `actionId` to the `Action` table without a default value. This is not possible if the table is not empty. - - Changed the type of `id` on the `Action` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `accessToken` on the `UserOAuth` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Added the required column `checksum` to the `WorkflowVersion` table without a default value. This is not possible if the table is not empty. - - Changed the type of `A` on the `_ActionToWorker` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - -*/ --- DropForeignKey -ALTER TABLE "Step" DROP CONSTRAINT "Step_actionId_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "_ActionToWorker" DROP CONSTRAINT "_ActionToWorker_A_fkey"; - --- DropIndex -DROP INDEX "Action_tenantId_id_key"; - --- DropIndex -DROP INDEX "WorkflowVersion_workflowId_version_key"; - --- AlterTable -ALTER TABLE "Action" DROP CONSTRAINT "Action_pkey", -ADD COLUMN "actionId" TEXT NOT NULL, -DROP COLUMN "id", -ADD COLUMN "id" UUID NOT NULL, -ADD CONSTRAINT "Action_pkey" PRIMARY KEY ("id"); - --- AlterTable -ALTER TABLE "UserOAuth" DROP COLUMN "accessToken", -ADD COLUMN "accessToken" BYTEA NOT NULL, -DROP COLUMN "refreshToken", -ADD COLUMN "refreshToken" BYTEA; - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "checksum" TEXT; - --- Add a default random string value to existing rows -UPDATE "WorkflowVersion" -SET "checksum" = md5(random()::text || clock_timestamp()::text); - --- Make the checksum column NOT NULL -ALTER TABLE "WorkflowVersion" ALTER COLUMN "checksum" SET NOT NULL; - --- Update the version column to allow NULL -ALTER TABLE "WorkflowVersion" ALTER COLUMN "version" DROP NOT NULL; - --- AlterTable -ALTER TABLE "_ActionToWorker" DROP COLUMN "A", -ADD COLUMN "A" UUID NOT NULL; - --- CreateTable -CREATE TABLE "APIToken" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "expiresAt" TIMESTAMP(3), - "revoked" BOOLEAN NOT NULL DEFAULT false, - "name" TEXT, - "tenantId" UUID, - - CONSTRAINT "APIToken_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "APIToken_id_key" ON "APIToken"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Action_id_key" ON "Action"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "Action_tenantId_actionId_key" ON "Action"("tenantId", "actionId"); - --- CreateIndex -CREATE UNIQUE INDEX "_ActionToWorker_AB_unique" ON "_ActionToWorker"("A", "B"); - --- AddForeignKey -ALTER TABLE "APIToken" ADD CONSTRAINT "APIToken_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "Step" ADD CONSTRAINT "Step_actionId_tenantId_fkey" FOREIGN KEY ("actionId", "tenantId") REFERENCES "Action"("actionId", "tenantId") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_ActionToWorker" ADD CONSTRAINT "_ActionToWorker_A_fkey" FOREIGN KEY ("A") REFERENCES "Action"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240129040510_v0_8_0/migration.sql b/prisma/migrations/20240129040510_v0_8_0/migration.sql deleted file mode 100644 index da82afdbd..000000000 --- a/prisma/migrations/20240129040510_v0_8_0/migration.sql +++ /dev/null @@ -1,79 +0,0 @@ --- CreateEnum -CREATE TYPE "ConcurrencyLimitStrategy" AS ENUM ('CANCEL_IN_PROGRESS', 'DROP_NEWEST', 'QUEUE_NEWEST'); - --- AlterEnum -ALTER TYPE "WorkflowRunStatus" ADD VALUE 'QUEUED'; - --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "concurrencyGroupId" TEXT; - --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "input" JSONB; - --- CreateTable -CREATE TABLE "WorkflowConcurrency" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "workflowVersionId" UUID NOT NULL, - "getConcurrencyGroupId" UUID, - "maxRuns" INTEGER NOT NULL DEFAULT 1, - "limitStrategy" "ConcurrencyLimitStrategy" NOT NULL DEFAULT 'CANCEL_IN_PROGRESS', - - CONSTRAINT "WorkflowConcurrency_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GetGroupKeyRun" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "workflowRunId" TEXT NOT NULL, - "workerId" UUID, - "tickerId" UUID, - "status" "StepRunStatus" NOT NULL DEFAULT 'PENDING', - "input" JSONB, - "output" TEXT, - "requeueAfter" TIMESTAMP(3), - "error" TEXT, - "startedAt" TIMESTAMP(3), - "finishedAt" TIMESTAMP(3), - "timeoutAt" TIMESTAMP(3), - "cancelledAt" TIMESTAMP(3), - "cancelledReason" TEXT, - "cancelledError" TEXT, - - CONSTRAINT "GetGroupKeyRun_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowConcurrency_id_key" ON "WorkflowConcurrency"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowConcurrency_workflowVersionId_key" ON "WorkflowConcurrency"("workflowVersionId"); - --- CreateIndex -CREATE UNIQUE INDEX "GetGroupKeyRun_id_key" ON "GetGroupKeyRun"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GetGroupKeyRun_tenantId_workflowRunId_key" ON "GetGroupKeyRun"("tenantId", "workflowRunId"); - --- AddForeignKey -ALTER TABLE "WorkflowConcurrency" ADD CONSTRAINT "WorkflowConcurrency_workflowVersionId_fkey" FOREIGN KEY ("workflowVersionId") REFERENCES "WorkflowVersion"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowConcurrency" ADD CONSTRAINT "WorkflowConcurrency_getConcurrencyGroupId_fkey" FOREIGN KEY ("getConcurrencyGroupId") REFERENCES "Action"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GetGroupKeyRun" ADD CONSTRAINT "GetGroupKeyRun_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GetGroupKeyRun" ADD CONSTRAINT "GetGroupKeyRun_tenantId_workflowRunId_fkey" FOREIGN KEY ("tenantId", "workflowRunId") REFERENCES "WorkflowRun"("tenantId", "id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GetGroupKeyRun" ADD CONSTRAINT "GetGroupKeyRun_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GetGroupKeyRun" ADD CONSTRAINT "GetGroupKeyRun_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20240202042355_v0_9_0/migration.sql b/prisma/migrations/20240202042355_v0_9_0/migration.sql deleted file mode 100644 index 7cf6bf655..000000000 --- a/prisma/migrations/20240202042355_v0_9_0/migration.sql +++ /dev/null @@ -1,67 +0,0 @@ -/* - Warnings: - - - The primary key for the `WorkflowRun` table will be changed. If it partially fails, the table could be left without primary key constraint. - - A unique constraint covering the columns `[workflowRunId]` on the table `GetGroupKeyRun` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[id]` on the table `WorkflowRun` will be added. If there are existing duplicate values, this will fail. - - Changed the type of `workflowRunId` on the `GetGroupKeyRun` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `workflowRunId` on the `JobRun` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `id` on the `WorkflowRun` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - - Changed the type of `parentId` on the `WorkflowRunTriggeredBy` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. - -*/ --- DropForeignKey -ALTER TABLE "GetGroupKeyRun" DROP CONSTRAINT "GetGroupKeyRun_tenantId_workflowRunId_fkey"; - --- DropForeignKey -ALTER TABLE "JobRun" DROP CONSTRAINT "JobRun_workflowRunId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" DROP CONSTRAINT "WorkflowRunTriggeredBy_parentId_fkey"; - --- DropIndex -DROP INDEX "GetGroupKeyRun_tenantId_workflowRunId_key"; - --- DropIndex -DROP INDEX "WorkflowRun_tenantId_id_key"; - --- DropIndex -DROP INDEX "WorkflowRunTriggeredBy_tenantId_parentId_key"; - --- AlterTable -ALTER TABLE "GetGroupKeyRun" DROP COLUMN "workflowRunId", -ADD COLUMN "workflowRunId" UUID NOT NULL; - --- AlterTable -ALTER TABLE "JobRun" DROP COLUMN "workflowRunId", -ADD COLUMN "workflowRunId" UUID NOT NULL; - --- AlterTable -ALTER TABLE "WorkflowRun" DROP CONSTRAINT "WorkflowRun_pkey", -ADD COLUMN "displayName" TEXT, -DROP COLUMN "id", -ADD COLUMN "id" UUID NOT NULL, -ADD CONSTRAINT "WorkflowRun_pkey" PRIMARY KEY ("id"); - --- AlterTable -ALTER TABLE "WorkflowRunTriggeredBy" ADD COLUMN "input" JSONB, -DROP COLUMN "parentId", -ADD COLUMN "parentId" UUID NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX "GetGroupKeyRun_workflowRunId_key" ON "GetGroupKeyRun"("workflowRunId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRun_id_key" ON "WorkflowRun"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunTriggeredBy_parentId_key" ON "WorkflowRunTriggeredBy"("parentId"); - --- AddForeignKey -ALTER TABLE "GetGroupKeyRun" ADD CONSTRAINT "GetGroupKeyRun_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "JobRun" ADD CONSTRAINT "JobRun_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240209132837_v0_10_0/migration.sql b/prisma/migrations/20240209132837_v0_10_0/migration.sql deleted file mode 100644 index 2d9507ab7..000000000 --- a/prisma/migrations/20240209132837_v0_10_0/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterTable -ALTER TABLE "Step" ADD COLUMN "customUserData" JSONB; - --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "inputSchema" JSONB; diff --git a/prisma/migrations/20240215162148_v0_10_2/migration.sql b/prisma/migrations/20240215162148_v0_10_2/migration.sql deleted file mode 100644 index 770d68023..000000000 --- a/prisma/migrations/20240215162148_v0_10_2/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ --- Create sequence and alter the table for StepRun -CREATE SEQUENCE step_run_order_seq; -ALTER TABLE "StepRun" ALTER COLUMN "order" TYPE BIGINT; -ALTER SEQUENCE step_run_order_seq OWNED BY "StepRun"."order"; -ALTER TABLE "StepRun" ALTER COLUMN "order" SET DEFAULT nextval('step_run_order_seq'::regclass); - --- Create sequence and alter the table for WorkflowVersion -CREATE SEQUENCE workflow_version_order_seq; -ALTER TABLE "WorkflowVersion" ALTER COLUMN "order" TYPE BIGINT; -ALTER SEQUENCE workflow_version_order_seq OWNED BY "WorkflowVersion"."order"; -ALTER TABLE "WorkflowVersion" ALTER COLUMN "order" SET DEFAULT nextval('workflow_version_order_seq'::regclass); - diff --git a/prisma/migrations/20240216133745_v0_11_0/migration.sql b/prisma/migrations/20240216133745_v0_11_0/migration.sql deleted file mode 100644 index 66e80d4f8..000000000 --- a/prisma/migrations/20240216133745_v0_11_0/migration.sql +++ /dev/null @@ -1,304 +0,0 @@ --- CreateEnum -CREATE TYPE "VcsProvider" AS ENUM ('GITHUB'); - --- AlterTable -ALTER TABLE "Step" ADD COLUMN "retries" INTEGER NOT NULL DEFAULT 0; - --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "callerFiles" JSONB, -ADD COLUMN "gitRepoBranch" TEXT, -ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0; - --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "gitRepoBranch" TEXT; - --- CreateTable -CREATE TABLE "WorkflowDeploymentConfig" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "workflowId" UUID NOT NULL, - "gitRepoName" TEXT NOT NULL, - "gitRepoOwner" TEXT NOT NULL, - "gitRepoBranch" TEXT NOT NULL, - "githubAppInstallationId" UUID, - - CONSTRAINT "WorkflowDeploymentConfig_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "StepRunResultArchive" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "stepRunId" UUID NOT NULL, - "order" BIGSERIAL NOT NULL, - "input" JSONB, - "output" JSONB, - "error" TEXT, - "startedAt" TIMESTAMP(3), - "finishedAt" TIMESTAMP(3), - "timeoutAt" TIMESTAMP(3), - "cancelledAt" TIMESTAMP(3), - "cancelledReason" TEXT, - "cancelledError" TEXT, - - CONSTRAINT "StepRunResultArchive_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TenantVcsProvider" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "vcsProvider" "VcsProvider" NOT NULL, - "config" JSONB, - - CONSTRAINT "TenantVcsProvider_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GithubAppInstallation" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "githubAppOAuthId" UUID NOT NULL, - "installationId" INTEGER NOT NULL, - "accountName" TEXT NOT NULL, - "accountId" INTEGER NOT NULL, - "accountAvatarURL" TEXT, - "installationSettingsURL" TEXT, - "config" JSONB, - "tenantId" UUID, - "tenantVcsProviderId" UUID, - - CONSTRAINT "GithubAppInstallation_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GithubAppOAuth" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "githubUserID" INTEGER NOT NULL, - "accessToken" BYTEA NOT NULL, - "refreshToken" BYTEA, - "expiresAt" TIMESTAMP(3), - - CONSTRAINT "GithubAppOAuth_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GithubPullRequest" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "repositoryOwner" TEXT NOT NULL, - "repositoryName" TEXT NOT NULL, - "pullRequestID" INTEGER NOT NULL, - "pullRequestTitle" TEXT NOT NULL, - "pullRequestNumber" INTEGER NOT NULL, - "pullRequestHeadBranch" TEXT NOT NULL, - "pullRequestBaseBranch" TEXT NOT NULL, - "pullRequestState" TEXT NOT NULL, - - CONSTRAINT "GithubPullRequest_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GithubPullRequestComment" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "pullRequestID" UUID NOT NULL, - "moduleID" TEXT NOT NULL, - "commentID" INTEGER NOT NULL, - - CONSTRAINT "GithubPullRequestComment_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "GithubWebhook" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "repositoryOwner" TEXT NOT NULL, - "repositoryName" TEXT NOT NULL, - "signingSecret" BYTEA NOT NULL, - - CONSTRAINT "GithubWebhook_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "_GithubAppInstallationToGithubWebhook" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_GithubAppOAuthToUser" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "_GithubPullRequestToWorkflowRun" ( - "A" UUID NOT NULL, - "B" UUID NOT NULL -); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowDeploymentConfig_id_key" ON "WorkflowDeploymentConfig"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowDeploymentConfig_workflowId_key" ON "WorkflowDeploymentConfig"("workflowId"); - --- CreateIndex -CREATE UNIQUE INDEX "StepRunResultArchive_id_key" ON "StepRunResultArchive"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantVcsProvider_id_key" ON "TenantVcsProvider"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantVcsProvider_tenantId_vcsProvider_key" ON "TenantVcsProvider"("tenantId", "vcsProvider"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubAppInstallation_id_key" ON "GithubAppInstallation"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubAppInstallation_installationId_accountId_key" ON "GithubAppInstallation"("installationId", "accountId"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubAppOAuth_id_key" ON "GithubAppOAuth"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubAppOAuth_githubUserID_key" ON "GithubAppOAuth"("githubUserID"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubPullRequest_id_key" ON "GithubPullRequest"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubPullRequest_tenantId_repositoryOwner_repositoryName_p_key" ON "GithubPullRequest"("tenantId", "repositoryOwner", "repositoryName", "pullRequestNumber"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubPullRequestComment_id_key" ON "GithubPullRequestComment"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubWebhook_id_key" ON "GithubWebhook"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "GithubWebhook_tenantId_repositoryOwner_repositoryName_key" ON "GithubWebhook"("tenantId", "repositoryOwner", "repositoryName"); - --- CreateIndex -CREATE UNIQUE INDEX "_GithubAppInstallationToGithubWebhook_AB_unique" ON "_GithubAppInstallationToGithubWebhook"("A", "B"); - --- CreateIndex -CREATE INDEX "_GithubAppInstallationToGithubWebhook_B_index" ON "_GithubAppInstallationToGithubWebhook"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_GithubAppOAuthToUser_AB_unique" ON "_GithubAppOAuthToUser"("A", "B"); - --- CreateIndex -CREATE INDEX "_GithubAppOAuthToUser_B_index" ON "_GithubAppOAuthToUser"("B"); - --- CreateIndex -CREATE UNIQUE INDEX "_GithubPullRequestToWorkflowRun_AB_unique" ON "_GithubPullRequestToWorkflowRun"("A", "B"); - --- CreateIndex -CREATE INDEX "_GithubPullRequestToWorkflowRun_B_index" ON "_GithubPullRequestToWorkflowRun"("B"); - --- AddForeignKey -ALTER TABLE "WorkflowDeploymentConfig" ADD CONSTRAINT "WorkflowDeploymentConfig_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "Workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowDeploymentConfig" ADD CONSTRAINT "WorkflowDeploymentConfig_githubAppInstallationId_fkey" FOREIGN KEY ("githubAppInstallationId") REFERENCES "GithubAppInstallation"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRunResultArchive" ADD CONSTRAINT "StepRunResultArchive_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantVcsProvider" ADD CONSTRAINT "TenantVcsProvider_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubAppInstallation" ADD CONSTRAINT "GithubAppInstallation_githubAppOAuthId_fkey" FOREIGN KEY ("githubAppOAuthId") REFERENCES "GithubAppOAuth"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubAppInstallation" ADD CONSTRAINT "GithubAppInstallation_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubAppInstallation" ADD CONSTRAINT "GithubAppInstallation_tenantVcsProviderId_fkey" FOREIGN KEY ("tenantVcsProviderId") REFERENCES "TenantVcsProvider"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubPullRequest" ADD CONSTRAINT "GithubPullRequest_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubPullRequestComment" ADD CONSTRAINT "GithubPullRequestComment_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubPullRequestComment" ADD CONSTRAINT "GithubPullRequestComment_pullRequestID_fkey" FOREIGN KEY ("pullRequestID") REFERENCES "GithubPullRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "GithubWebhook" ADD CONSTRAINT "GithubWebhook_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubAppInstallationToGithubWebhook" ADD CONSTRAINT "_GithubAppInstallationToGithubWebhook_A_fkey" FOREIGN KEY ("A") REFERENCES "GithubAppInstallation"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubAppInstallationToGithubWebhook" ADD CONSTRAINT "_GithubAppInstallationToGithubWebhook_B_fkey" FOREIGN KEY ("B") REFERENCES "GithubWebhook"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubAppOAuthToUser" ADD CONSTRAINT "_GithubAppOAuthToUser_A_fkey" FOREIGN KEY ("A") REFERENCES "GithubAppOAuth"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubAppOAuthToUser" ADD CONSTRAINT "_GithubAppOAuthToUser_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubPullRequestToWorkflowRun" ADD CONSTRAINT "_GithubPullRequestToWorkflowRun_A_fkey" FOREIGN KEY ("A") REFERENCES "GithubPullRequest"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "_GithubPullRequestToWorkflowRun" ADD CONSTRAINT "_GithubPullRequestToWorkflowRun_B_fkey" FOREIGN KEY ("B") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - -INSERT INTO - "Tenant" ( - "id", - "createdAt", - "updatedAt", - "deletedAt", - "name", - "slug" - ) -VALUES - ( - '8d420720-ef03-41dc-9c73-1c93f276db97', - CURRENT_TIMESTAMP, - CURRENT_TIMESTAMP, - NULL, - 'internal', - 'internal' - ) ON CONFLICT DO NOTHING; - -CREATE OR REPLACE FUNCTION prevent_internal_name_or_slug() -RETURNS trigger AS $$ -BEGIN - IF NEW."name" = 'internal' OR NEW."slug" = 'internal' THEN - RAISE EXCEPTION 'Values "internal" for "name" or "slug" are not allowed.'; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER check_name_or_slug_before_insert_or_update -BEFORE INSERT OR UPDATE ON "Tenant" -FOR EACH ROW EXECUTE FUNCTION prevent_internal_name_or_slug(); \ No newline at end of file diff --git a/prisma/migrations/20240226051822_v0_12_0/migration.sql b/prisma/migrations/20240226051822_v0_12_0/migration.sql deleted file mode 100644 index c9a23a476..000000000 --- a/prisma/migrations/20240226051822_v0_12_0/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterEnum -ALTER TYPE "ConcurrencyLimitStrategy" ADD VALUE 'GROUP_ROUND_ROBIN'; - --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "maxRuns" INTEGER; diff --git a/prisma/migrations/20240227181732_v0_13_0/migration.sql b/prisma/migrations/20240227181732_v0_13_0/migration.sql deleted file mode 100644 index 9fbb9e533..000000000 --- a/prisma/migrations/20240227181732_v0_13_0/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- DropForeignKey -ALTER TABLE "Worker" DROP CONSTRAINT "Worker_dispatcherId_fkey"; - --- AlterTable -ALTER TABLE "Worker" ALTER COLUMN "dispatcherId" DROP NOT NULL; - --- AddForeignKey -ALTER TABLE "Worker" ADD CONSTRAINT "Worker_dispatcherId_fkey" FOREIGN KEY ("dispatcherId") REFERENCES "Dispatcher"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20240228050417_v0_13_2/migration.sql b/prisma/migrations/20240228050417_v0_13_2/migration.sql deleted file mode 100644 index 98726c99e..000000000 --- a/prisma/migrations/20240228050417_v0_13_2/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- AlterTable -ALTER TABLE "GetGroupKeyRun" ADD COLUMN "scheduleTimeoutAt" TIMESTAMP(3); - --- AlterTable -ALTER TABLE "Step" ADD COLUMN "scheduleTimeout" TEXT NOT NULL DEFAULT '5m'; - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "scheduleTimeout" TEXT NOT NULL DEFAULT '5m'; diff --git a/prisma/migrations/20240229232811_v0_14_0/migration.sql b/prisma/migrations/20240229232811_v0_14_0/migration.sql deleted file mode 100644 index d1e9d658b..000000000 --- a/prisma/migrations/20240229232811_v0_14_0/migration.sql +++ /dev/null @@ -1,21 +0,0 @@ --- CreateEnum -CREATE TYPE "LogLineLevel" AS ENUM ('DEBUG', 'INFO', 'WARN', 'ERROR'); - --- CreateTable -CREATE TABLE - "LogLine" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "stepRunId" UUID, - "message" TEXT NOT NULL, - "level" "LogLineLevel" NOT NULL DEFAULT 'INFO', - "metadata" JSONB, - CONSTRAINT "LogLine_pkey" PRIMARY KEY ("id") - ); - --- AddForeignKey -ALTER TABLE "LogLine" ADD CONSTRAINT "LogLine_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant" ("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "LogLine" ADD CONSTRAINT "LogLine_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun" ("id") ON DELETE SET NULL ON UPDATE CASCADE; \ No newline at end of file diff --git a/prisma/migrations/20240304060408_v0_15_0/migration.sql b/prisma/migrations/20240304060408_v0_15_0/migration.sql deleted file mode 100644 index c67d69611..000000000 --- a/prisma/migrations/20240304060408_v0_15_0/migration.sql +++ /dev/null @@ -1,19 +0,0 @@ --- CreateTable -CREATE TABLE "SNSIntegration" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "topicArn" TEXT NOT NULL, - - CONSTRAINT "SNSIntegration_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "SNSIntegration_id_key" ON "SNSIntegration"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "SNSIntegration_tenantId_topicArn_key" ON "SNSIntegration"("tenantId", "topicArn"); - --- AddForeignKey -ALTER TABLE "SNSIntegration" ADD CONSTRAINT "SNSIntegration_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240320215205_v0_17_0/migration.sql b/prisma/migrations/20240320215205_v0_17_0/migration.sql deleted file mode 100644 index 101d0e2a5..000000000 --- a/prisma/migrations/20240320215205_v0_17_0/migration.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE FUNCTION convert_duration_to_interval(duration text) RETURNS interval AS $$ -DECLARE - num_value INT; -BEGIN - num_value := substring(duration from '^\d+'); - - RETURN CASE - WHEN duration LIKE '%ms' THEN make_interval(secs => num_value::float / 1000) - WHEN duration LIKE '%s' THEN make_interval(secs => num_value) - WHEN duration LIKE '%m' THEN make_interval(mins => num_value) - WHEN duration LIKE '%h' THEN make_interval(hours => num_value) - WHEN duration LIKE '%d' THEN make_interval(days => num_value) - WHEN duration LIKE '%w' THEN make_interval(days => num_value * 7) - WHEN duration LIKE '%y' THEN make_interval(months => num_value * 12) - ELSE '0 seconds'::interval - END; -END; -$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/prisma/migrations/20240321215205_v0_17_1/migration.sql b/prisma/migrations/20240321215205_v0_17_1/migration.sql deleted file mode 100644 index 6bcc6f12c..000000000 --- a/prisma/migrations/20240321215205_v0_17_1/migration.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE FUNCTION convert_duration_to_interval(duration text) RETURNS interval AS $$ -DECLARE - num_value INT; -BEGIN - num_value := substring(duration from '^\d+'); - - RETURN CASE - WHEN duration LIKE '%ms' THEN make_interval(secs => num_value::float / 1000) - WHEN duration LIKE '%s' THEN make_interval(secs => num_value) - WHEN duration LIKE '%m' THEN make_interval(mins => num_value) - WHEN duration LIKE '%h' THEN make_interval(hours => num_value) - WHEN duration LIKE '%d' THEN make_interval(days => num_value) - WHEN duration LIKE '%w' THEN make_interval(days => num_value * 7) - WHEN duration LIKE '%y' THEN make_interval(months => num_value * 12) - ELSE '5 minutes'::interval - END; -END; -$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/prisma/migrations/20240326151030_v0_18_0/migration.sql b/prisma/migrations/20240326151030_v0_18_0/migration.sql deleted file mode 100644 index 23794c4ca..000000000 --- a/prisma/migrations/20240326151030_v0_18_0/migration.sql +++ /dev/null @@ -1,36 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[parentId,parentStepRunId,childKey]` on the table `WorkflowRun` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[parentId,parentStepRunId,childKey]` on the table `WorkflowTriggerScheduledRef` will be added. If there are existing duplicate values, this will fail. - -*/ --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "childIndex" INTEGER, -ADD COLUMN "childKey" TEXT, -ADD COLUMN "parentId" UUID, -ADD COLUMN "parentStepRunId" UUID; - --- AlterTable -ALTER TABLE "WorkflowTriggerScheduledRef" ADD COLUMN "childIndex" INTEGER, -ADD COLUMN "childKey" TEXT, -ADD COLUMN "parentStepRunId" UUID, -ADD COLUMN "parentWorkflowRunId" UUID; - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRun_parentId_parentStepRunId_childKey_key" ON "WorkflowRun"("parentId", "parentStepRunId", "childKey"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerScheduledRef_parentId_parentStepRunId_childK_key" ON "WorkflowTriggerScheduledRef"("parentId", "parentStepRunId", "childKey"); - --- AddForeignKey -ALTER TABLE "WorkflowTriggerScheduledRef" ADD CONSTRAINT "WorkflowTriggerScheduledRef_parentWorkflowRunId_fkey" FOREIGN KEY ("parentWorkflowRunId") REFERENCES "WorkflowRun"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowTriggerScheduledRef" ADD CONSTRAINT "WorkflowTriggerScheduledRef_parentStepRunId_fkey" FOREIGN KEY ("parentStepRunId") REFERENCES "StepRun"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRun" ADD CONSTRAINT "WorkflowRun_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "WorkflowRun"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRun" ADD CONSTRAINT "WorkflowRun_parentStepRunId_fkey" FOREIGN KEY ("parentStepRunId") REFERENCES "StepRun"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20240331162333_v0_18_1/migration.sql b/prisma/migrations/20240331162333_v0_18_1/migration.sql deleted file mode 100644 index b4a5879c1..000000000 --- a/prisma/migrations/20240331162333_v0_18_1/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ --- CreateTable -CREATE TABLE "WorkerSemaphore" ( - "workerId" UUID NOT NULL, - "slots" INTEGER NOT NULL -); - --- CreateIndex -CREATE UNIQUE INDEX "WorkerSemaphore_workerId_key" ON "WorkerSemaphore"("workerId"); - --- AddForeignKey -ALTER TABLE "WorkerSemaphore" ADD CONSTRAINT "WorkerSemaphore_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240402034010_v0_19_0/migration.sql b/prisma/migrations/20240402034010_v0_19_0/migration.sql deleted file mode 100644 index b87b525f9..000000000 --- a/prisma/migrations/20240402034010_v0_19_0/migration.sql +++ /dev/null @@ -1,67 +0,0 @@ --- CreateTable -CREATE TABLE "StepRateLimit" ( - "units" INTEGER NOT NULL, - "stepId" UUID NOT NULL, - "rateLimitKey" TEXT NOT NULL, - "tenantId" UUID NOT NULL -); - --- CreateTable -CREATE TABLE "RateLimit" ( - "tenantId" UUID NOT NULL, - "key" TEXT NOT NULL, - "limitValue" INTEGER NOT NULL, - "value" INTEGER NOT NULL, - "window" TEXT NOT NULL, - "lastRefill" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP -); - --- CreateTable -CREATE TABLE "StreamEvent" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "stepRunId" UUID, - "message" BYTEA NOT NULL, - "metadata" JSONB, - - CONSTRAINT "StreamEvent_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "StepRateLimit_stepId_rateLimitKey_key" ON "StepRateLimit"("stepId", "rateLimitKey"); - --- CreateIndex -CREATE UNIQUE INDEX "RateLimit_tenantId_key_key" ON "RateLimit"("tenantId", "key"); - --- AddForeignKey -ALTER TABLE "StepRateLimit" ADD CONSTRAINT "StepRateLimit_stepId_fkey" FOREIGN KEY ("stepId") REFERENCES "Step"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRateLimit" ADD CONSTRAINT "StepRateLimit_tenantId_rateLimitKey_fkey" FOREIGN KEY ("tenantId", "rateLimitKey") REFERENCES "RateLimit"("tenantId", "key") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StepRateLimit" ADD CONSTRAINT "StepRateLimit_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "RateLimit" ADD CONSTRAINT "RateLimit_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StreamEvent" ADD CONSTRAINT "StreamEvent_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "StreamEvent" ADD CONSTRAINT "StreamEvent_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun"("id") ON DELETE SET NULL ON UPDATE CASCADE; - -CREATE OR REPLACE FUNCTION get_refill_value(rate_limit "RateLimit") -RETURNS INTEGER AS $$ -DECLARE - refill_amount INTEGER; -BEGIN - IF NOW() - rate_limit."lastRefill" >= rate_limit."window"::INTERVAL THEN - refill_amount := rate_limit."limitValue"; - ELSE - refill_amount := rate_limit."value"; - END IF; - RETURN refill_amount; -END; -$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/prisma/migrations/20240424091046_v0_21_9/migration.sql b/prisma/migrations/20240424091046_v0_21_9/migration.sql deleted file mode 100644 index 7346db4ea..000000000 --- a/prisma/migrations/20240424091046_v0_21_9/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true; diff --git a/prisma/migrations/20240430161943_v0_22_1/migration.sql b/prisma/migrations/20240430161943_v0_22_1/migration.sql deleted file mode 100644 index d23aac8b0..000000000 --- a/prisma/migrations/20240430161943_v0_22_1/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `status` on the `Worker` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "Worker" DROP COLUMN "status"; - --- DropEnum -DROP TYPE "WorkerStatus"; diff --git a/prisma/migrations/20240503190030_v0_23_0/migration.sql b/prisma/migrations/20240503190030_v0_23_0/migration.sql deleted file mode 100644 index fb677a4d5..000000000 --- a/prisma/migrations/20240503190030_v0_23_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Tenant" ADD COLUMN "analyticsOptOut" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240506194242_v0_24_0/migration.sql b/prisma/migrations/20240506194242_v0_24_0/migration.sql deleted file mode 100644 index 908490242..000000000 --- a/prisma/migrations/20240506194242_v0_24_0/migration.sql +++ /dev/null @@ -1,26 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[onFailureJobId]` on the table `WorkflowVersion` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateEnum -CREATE TYPE "JobKind" AS ENUM ('DEFAULT', 'ON_FAILURE'); - --- AlterTable -ALTER TABLE "Event" ADD COLUMN "additionalMetadata" JSONB; - --- AlterTable -ALTER TABLE "Job" ADD COLUMN "kind" "JobKind" NOT NULL DEFAULT 'DEFAULT'; - --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "additionalMetadata" JSONB; - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "onFailureJobId" UUID; - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowVersion_onFailureJobId_key" ON "WorkflowVersion"("onFailureJobId"); - --- AddForeignKey -ALTER TABLE "WorkflowVersion" ADD CONSTRAINT "WorkflowVersion_onFailureJobId_fkey" FOREIGN KEY ("onFailureJobId") REFERENCES "Job"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20240507200816_v0_25_0/migration.sql b/prisma/migrations/20240507200816_v0_25_0/migration.sql deleted file mode 100644 index 8422e38b2..000000000 --- a/prisma/migrations/20240507200816_v0_25_0/migration.sql +++ /dev/null @@ -1,77 +0,0 @@ --- CreateTable -CREATE TABLE - "TenantAlertingSettings" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "maxFrequency" TEXT NOT NULL DEFAULT '1h', - "lastAlertedAt" TIMESTAMP(3), - "tickerId" UUID, - CONSTRAINT "TenantAlertingSettings_pkey" PRIMARY KEY ("id") - ); - --- CreateTable -CREATE TABLE - "TenantAlertEmailGroup" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "emails" TEXT NOT NULL, - CONSTRAINT "TenantAlertEmailGroup_pkey" PRIMARY KEY ("id") - ); - --- CreateTable -CREATE TABLE - "SlackAppWebhook" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "teamId" TEXT NOT NULL, - "teamName" TEXT NOT NULL, - "channelId" TEXT NOT NULL, - "channelName" TEXT NOT NULL, - "webhookURL" BYTEA NOT NULL, - CONSTRAINT "SlackAppWebhook_pkey" PRIMARY KEY ("id") - ); - --- CreateIndex -CREATE UNIQUE INDEX "TenantAlertingSettings_id_key" ON "TenantAlertingSettings" ("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantAlertingSettings_tenantId_key" ON "TenantAlertingSettings" ("tenantId"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantAlertEmailGroup_id_key" ON "TenantAlertEmailGroup" ("id"); - --- CreateIndex -CREATE UNIQUE INDEX "SlackAppWebhook_id_key" ON "SlackAppWebhook" ("id"); - --- CreateIndex -CREATE UNIQUE INDEX "SlackAppWebhook_tenantId_teamId_channelId_key" ON "SlackAppWebhook" ("tenantId", "teamId", "channelId"); - --- AddForeignKey -ALTER TABLE "TenantAlertingSettings" ADD CONSTRAINT "TenantAlertingSettings_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant" ("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantAlertingSettings" ADD CONSTRAINT "TenantAlertingSettings_tickerId_fkey" FOREIGN KEY ("tickerId") REFERENCES "Ticker" ("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantAlertEmailGroup" ADD CONSTRAINT "TenantAlertEmailGroup_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant" ("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "SlackAppWebhook" ADD CONSTRAINT "SlackAppWebhook_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant" ("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- Insert "TenantAlertingSettings" for every existing tenant -INSERT INTO - "TenantAlertingSettings" ("id", "tenantId") -SELECT - gen_random_uuid (), - "id" -FROM - "Tenant"; \ No newline at end of file diff --git a/prisma/migrations/20240509213608_v0_26_0/migration.sql b/prisma/migrations/20240509213608_v0_26_0/migration.sql deleted file mode 100644 index 8921c6f60..000000000 --- a/prisma/migrations/20240509213608_v0_26_0/migration.sql +++ /dev/null @@ -1,56 +0,0 @@ --- CreateIndex -CREATE INDEX "JobRun_workflowRunId_tenantId_idx" ON "JobRun" ("workflowRunId", "tenantId"); - --- CreateIndex -CREATE INDEX "StepRun_tenantId_status_requeueAfter_createdAt_idx" ON "StepRun" ("tenantId", "status", "requeueAfter", "createdAt"); - --- CreateIndex -CREATE INDEX "StepRun_stepId_idx" ON "StepRun" ("stepId"); - --- CreateIndex -CREATE INDEX "StepRun_jobRunId_status_idx" ON "StepRun" ("jobRunId", "status"); - --- CreateIndex -CREATE INDEX "StepRun_id_tenantId_idx" ON "StepRun" ("id", "tenantId"); - --- CreateIndex -CREATE INDEX "StepRun_jobRunId_tenantId_order_idx" ON "StepRun" ("jobRunId", "tenantId", "order"); - --- CreateEnum -CREATE TYPE "StepRunEventReason" AS ENUM ( - 'REQUEUED_NO_WORKER', - 'REQUEUED_RATE_LIMIT', - 'SCHEDULING_TIMED_OUT', - 'ASSIGNED', - 'STARTED', - 'FINISHED', - 'FAILED', - 'RETRYING', - 'CANCELLED' -); - --- CreateEnum -CREATE TYPE "StepRunEventSeverity" AS ENUM ('INFO', 'WARNING', 'CRITICAL'); - --- CreateTable -CREATE TABLE - "StepRunEvent" ( - "id" BIGSERIAL NOT NULL, - "timeFirstSeen" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "timeLastSeen" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "stepRunId" UUID NOT NULL, - "reason" "StepRunEventReason" NOT NULL, - "severity" "StepRunEventSeverity" NOT NULL, - "message" TEXT NOT NULL, - "count" INTEGER NOT NULL, - "data" JSONB - ); - --- CreateIndex -CREATE UNIQUE INDEX "StepRunEvent_id_key" ON "StepRunEvent" ("id"); - --- CreateIndex -CREATE INDEX "StepRunEvent_stepRunId_idx" ON "StepRunEvent" ("stepRunId"); - --- AddForeignKey -ALTER TABLE "StepRunEvent" ADD CONSTRAINT "StepRunEvent_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun" ("id") ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file diff --git a/prisma/migrations/20240514192527_v0_27_0/migration.sql b/prisma/migrations/20240514192527_v0_27_0/migration.sql deleted file mode 100644 index 666ae42c1..000000000 --- a/prisma/migrations/20240514192527_v0_27_0/migration.sql +++ /dev/null @@ -1,14 +0,0 @@ --- AlterEnum --- This migration adds more than one value to an enum. --- With PostgreSQL versions 11 and earlier, this is not possible --- in a single migration. This can be worked around by creating --- multiple migrations, each migration adding only one value to --- the enum. - - -ALTER TYPE "StepRunEventReason" ADD VALUE 'TIMED_OUT'; -ALTER TYPE "StepRunEventReason" ADD VALUE 'REASSIGNED'; -ALTER TYPE "StepRunEventReason" ADD VALUE 'SLOT_RELEASED'; - --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "semaphoreReleased" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240514203126_v0_28_0/migration.sql b/prisma/migrations/20240514203126_v0_28_0/migration.sql deleted file mode 100644 index e90289267..000000000 --- a/prisma/migrations/20240514203126_v0_28_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterEnum -ALTER TYPE "StepRunEventReason" ADD VALUE 'TIMEOUT_REFRESHED'; diff --git a/prisma/migrations/20240517204453_v0_28_1/migration.sql b/prisma/migrations/20240517204453_v0_28_1/migration.sql deleted file mode 100644 index 9b806a59c..000000000 --- a/prisma/migrations/20240517204453_v0_28_1/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterEnum -ALTER TYPE "StepRunEventReason" ADD VALUE 'RETRIED_BY_USER'; diff --git a/prisma/migrations/20240520152239_v0_28_2/migration.sql b/prisma/migrations/20240520152239_v0_28_2/migration.sql deleted file mode 100644 index 06c6fbf79..000000000 --- a/prisma/migrations/20240520152239_v0_28_2/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240521205311_v0_28_3/migration.sql b/prisma/migrations/20240521205311_v0_28_3/migration.sql deleted file mode 100644 index d906f42a7..000000000 --- a/prisma/migrations/20240521205311_v0_28_3/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "lastListenerEstablished" TIMESTAMP(3); diff --git a/prisma/migrations/20240531142907_v0_29_0/migration.sql b/prisma/migrations/20240531142907_v0_29_0/migration.sql deleted file mode 100644 index ce38b85c6..000000000 --- a/prisma/migrations/20240531142907_v0_29_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "APIToken" ADD COLUMN "nextAlertAt" TIMESTAMP(3); diff --git a/prisma/migrations/20240531200417_v_0_30_0/migration.sql b/prisma/migrations/20240531200417_v_0_30_0/migration.sql deleted file mode 100644 index 92e9c6a85..000000000 --- a/prisma/migrations/20240531200417_v_0_30_0/migration.sql +++ /dev/null @@ -1,6 +0,0 @@ --- AlterTable -ALTER TABLE "Tenant" ADD COLUMN "alertMemberEmails" BOOLEAN NOT NULL DEFAULT true; - --- AlterTable -ALTER TABLE "TenantAlertingSettings" ADD COLUMN "enableExpiringTokenAlerts" BOOLEAN NOT NULL DEFAULT true, -ADD COLUMN "enableWorkflowRunFailureAlerts" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240531200418_v0_30_1/migration.sql b/prisma/migrations/20240531200418_v0_30_1/migration.sql deleted file mode 100644 index b5984b090..000000000 --- a/prisma/migrations/20240531200418_v0_30_1/migration.sql +++ /dev/null @@ -1,78 +0,0 @@ -/* Warnings: -- You are about to drop the `WorkerSemaphore` table. If the table is not empty, all the data it contains will be lost. -- Made the column `maxRuns` on table `Worker` required. This step will fail if there are existing NULL values in that column. -*/ - - --- Update existing workers with NULL maxRuns to have a default value -UPDATE "Worker" SET "maxRuns" = 100 WHERE "maxRuns" IS NULL; - --- AlterTable -ALTER TABLE "Worker" ALTER COLUMN "maxRuns" SET NOT NULL, - ALTER COLUMN "maxRuns" SET DEFAULT 100; - --- CreateTable -CREATE TABLE IF NOT EXISTS "WorkerSemaphoreSlot" ( - "id" UUID NOT NULL, - "workerId" UUID NOT NULL, - "stepRunId" UUID, - CONSTRAINT "WorkerSemaphoreSlot_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX IF NOT EXISTS "WorkerSemaphoreSlot_id_key" ON "WorkerSemaphoreSlot"("id"); - --- CreateIndex -CREATE UNIQUE INDEX IF NOT EXISTS "WorkerSemaphoreSlot_stepRunId_key" ON "WorkerSemaphoreSlot"("stepRunId"); - --- AddForeignKey -ALTER TABLE "WorkerSemaphoreSlot" -ADD CONSTRAINT "WorkerSemaphoreSlot_workerId_fkey" -FOREIGN KEY ("workerId") REFERENCES "Worker"("id") -ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkerSemaphoreSlot" -ADD CONSTRAINT "WorkerSemaphoreSlot_stepRunId_fkey" -FOREIGN KEY ("stepRunId") REFERENCES "StepRun"("id") -ON DELETE CASCADE ON UPDATE CASCADE; - --- CreateIndex -CREATE INDEX "WorkerSemaphoreSlot_workerId_idx" ON "WorkerSemaphoreSlot"("workerId"); - --- Create maxRun semaphore slots for each worker with a recent heartbeat -INSERT INTO "WorkerSemaphoreSlot" ("id", "workerId") -SELECT gen_random_uuid(), w.id -FROM "Worker" w -CROSS JOIN generate_series(1, COALESCE(w."maxRuns", 100)) -WHERE w."lastHeartbeatAt" >= NOW() - INTERVAL '10 hours' -ON CONFLICT DO NOTHING; - --- -- Update a null slot for each step that is currently running or assigned -DO $$ -DECLARE - sr RECORD; - wss RECORD; -BEGIN - -- Loop over each running or assigned step run - FOR sr IN - SELECT "id", "workerId" - FROM "StepRun" - WHERE "status" IN ('RUNNING', 'ASSIGNED') - LOOP - -- Find one available WorkerSemaphoreSlot for the current workerId - SELECT "id" - INTO wss - FROM "WorkerSemaphoreSlot" - WHERE "workerId" = sr."workerId" AND "stepRunId" IS NULL - LIMIT 1; - - -- If an available slot is found, update it with the stepRunId - IF wss.id IS NOT NULL THEN - UPDATE "WorkerSemaphoreSlot" - SET "stepRunId" = sr.id - WHERE "id" = wss.id; - END IF; - END LOOP; -END $$; - diff --git a/prisma/migrations/20240606145243_v0_31_0/migration.sql b/prisma/migrations/20240606145243_v0_31_0/migration.sql deleted file mode 100644 index 64b8fc991..000000000 --- a/prisma/migrations/20240606145243_v0_31_0/migration.sql +++ /dev/null @@ -1,58 +0,0 @@ --- CreateEnum -CREATE TYPE "LimitResource" AS ENUM ('WORKFLOW_RUN', 'EVENT', 'WORKER', 'CRON', 'SCHEDULE'); - --- CreateEnum -CREATE TYPE "TenantResourceLimitAlertType" AS ENUM ('Alarm', 'Exhausted'); - --- AlterTable -ALTER TABLE "TenantAlertingSettings" ADD COLUMN "enableTenantResourceLimitAlerts" BOOLEAN NOT NULL DEFAULT true; - --- CreateTable -CREATE TABLE "TenantResourceLimit" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "resource" "LimitResource" NOT NULL, - "tenantId" UUID NOT NULL, - "limitValue" INTEGER NOT NULL, - "alarmValue" INTEGER, - "value" INTEGER NOT NULL DEFAULT 0, - "window" TEXT, - "lastRefill" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "customValueMeter" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "TenantResourceLimit_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TenantResourceLimitAlert" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "resourceLimitId" UUID NOT NULL, - "tenantId" UUID NOT NULL, - "resource" "LimitResource" NOT NULL, - "alertType" "TenantResourceLimitAlertType" NOT NULL, - "value" INTEGER NOT NULL, - "limit" INTEGER NOT NULL, - - CONSTRAINT "TenantResourceLimitAlert_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "TenantResourceLimit_id_key" ON "TenantResourceLimit"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantResourceLimit_tenantId_resource_key" ON "TenantResourceLimit"("tenantId", "resource"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantResourceLimitAlert_id_key" ON "TenantResourceLimitAlert"("id"); - --- AddForeignKey -ALTER TABLE "TenantResourceLimit" ADD CONSTRAINT "TenantResourceLimit_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantResourceLimitAlert" ADD CONSTRAINT "TenantResourceLimitAlert_resourceLimitId_fkey" FOREIGN KEY ("resourceLimitId") REFERENCES "TenantResourceLimit"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "TenantResourceLimitAlert" ADD CONSTRAINT "TenantResourceLimitAlert_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240625180539_v0_34_0/migration.sql b/prisma/migrations/20240625180539_v0_34_0/migration.sql deleted file mode 100644 index 4866990b6..000000000 --- a/prisma/migrations/20240625180539_v0_34_0/migration.sql +++ /dev/null @@ -1,138 +0,0 @@ -/* - Warnings: - - - You are about to drop the column `gitRepoBranch` on the `WorkflowRun` table. All the data in the column will be lost. - - You are about to drop the `GithubAppInstallation` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `GithubAppOAuth` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `GithubPullRequest` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `GithubPullRequestComment` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `GithubWebhook` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `WorkflowDeploymentConfig` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `_GithubAppInstallationToGithubWebhook` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `_GithubAppOAuthToUser` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `_GithubPullRequestToWorkflowRun` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropForeignKey -ALTER TABLE "GithubAppInstallation" DROP CONSTRAINT "GithubAppInstallation_githubAppOAuthId_fkey"; - --- DropForeignKey -ALTER TABLE "GithubAppInstallation" DROP CONSTRAINT "GithubAppInstallation_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "GithubAppInstallation" DROP CONSTRAINT "GithubAppInstallation_tenantVcsProviderId_fkey"; - --- DropForeignKey -ALTER TABLE "GithubPullRequest" DROP CONSTRAINT "GithubPullRequest_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "GithubPullRequestComment" DROP CONSTRAINT "GithubPullRequestComment_pullRequestID_fkey"; - --- DropForeignKey -ALTER TABLE "GithubPullRequestComment" DROP CONSTRAINT "GithubPullRequestComment_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "GithubWebhook" DROP CONSTRAINT "GithubWebhook_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowDeploymentConfig" DROP CONSTRAINT "WorkflowDeploymentConfig_githubAppInstallationId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowDeploymentConfig" DROP CONSTRAINT "WorkflowDeploymentConfig_workflowId_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubAppInstallationToGithubWebhook" DROP CONSTRAINT "_GithubAppInstallationToGithubWebhook_A_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubAppInstallationToGithubWebhook" DROP CONSTRAINT "_GithubAppInstallationToGithubWebhook_B_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubAppOAuthToUser" DROP CONSTRAINT "_GithubAppOAuthToUser_A_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubAppOAuthToUser" DROP CONSTRAINT "_GithubAppOAuthToUser_B_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubPullRequestToWorkflowRun" DROP CONSTRAINT "_GithubPullRequestToWorkflowRun_A_fkey"; - --- DropForeignKey -ALTER TABLE "_GithubPullRequestToWorkflowRun" DROP CONSTRAINT "_GithubPullRequestToWorkflowRun_B_fkey"; - --- AlterTable -ALTER TABLE "WorkflowRun" DROP COLUMN "gitRepoBranch"; - --- DropTable -DROP TABLE "GithubAppInstallation"; - --- DropTable -DROP TABLE "GithubAppOAuth"; - --- DropTable -DROP TABLE "GithubPullRequest"; - --- DropTable -DROP TABLE "GithubPullRequestComment"; - --- DropTable -DROP TABLE "GithubWebhook"; - --- DropTable -DROP TABLE "WorkflowDeploymentConfig"; - --- DropTable -DROP TABLE "_GithubAppInstallationToGithubWebhook"; - --- DropTable -DROP TABLE "_GithubAppOAuthToUser"; - --- DropTable -DROP TABLE "_GithubPullRequestToWorkflowRun"; - --- CreateTable -CREATE TABLE "WebhookWorker" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "name" TEXT NOT NULL, - "secret" TEXT NOT NULL, - "url" TEXT NOT NULL, - "tokenValue" TEXT, - "deleted" BOOLEAN NOT NULL DEFAULT false, - "tokenId" UUID, - "tenantId" UUID NOT NULL, - - CONSTRAINT "WebhookWorker_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WebhookWorkerWorkflow" ( - "id" UUID NOT NULL, - "webhookWorkerId" UUID NOT NULL, - "workflowId" UUID NOT NULL, - - CONSTRAINT "WebhookWorkerWorkflow_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "WebhookWorker_id_key" ON "WebhookWorker"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WebhookWorker_url_key" ON "WebhookWorker"("url"); - --- CreateIndex -CREATE UNIQUE INDEX "WebhookWorkerWorkflow_id_key" ON "WebhookWorkerWorkflow"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WebhookWorkerWorkflow_webhookWorkerId_workflowId_key" ON "WebhookWorkerWorkflow"("webhookWorkerId", "workflowId"); - --- AddForeignKey -ALTER TABLE "WebhookWorker" ADD CONSTRAINT "WebhookWorker_tokenId_fkey" FOREIGN KEY ("tokenId") REFERENCES "APIToken"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WebhookWorker" ADD CONSTRAINT "WebhookWorker_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WebhookWorkerWorkflow" ADD CONSTRAINT "WebhookWorkerWorkflow_webhookWorkerId_fkey" FOREIGN KEY ("webhookWorkerId") REFERENCES "WebhookWorker"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WebhookWorkerWorkflow" ADD CONSTRAINT "WebhookWorkerWorkflow_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "Workflow"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240626204332_v0_34_2/migration.sql b/prisma/migrations/20240626204332_v0_34_2/migration.sql deleted file mode 100644 index b0460f97b..000000000 --- a/prisma/migrations/20240626204332_v0_34_2/migration.sql +++ /dev/null @@ -1,51 +0,0 @@ --- AlterTable -ALTER TABLE "Tenant" ADD COLUMN "controllerPartitionId" TEXT, -ADD COLUMN "workerPartitionId" TEXT; - --- CreateTable -CREATE TABLE "ControllerPartition" ( - "id" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastHeartbeat" TIMESTAMP(3), - - CONSTRAINT "ControllerPartition_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "TenantWorkerPartition" ( - "id" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastHeartbeat" TIMESTAMP(3), - - CONSTRAINT "TenantWorkerPartition_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "SecurityCheckIdent" ( - "id" UUID NOT NULL, - - CONSTRAINT "SecurityCheckIdent_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "ControllerPartition_id_key" ON "ControllerPartition"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "TenantWorkerPartition_id_key" ON "TenantWorkerPartition"("id"); - --- CreateIndex -CREATE UNIQUE INDEX "SecurityCheckIdent_id_key" ON "SecurityCheckIdent"("id"); - --- CreateIndex -CREATE INDEX "Tenant_controllerPartitionId_idx" ON "Tenant"("controllerPartitionId"); - --- CreateIndex -CREATE INDEX "Tenant_workerPartitionId_idx" ON "Tenant"("workerPartitionId"); - --- AddForeignKey -ALTER TABLE "Tenant" ADD CONSTRAINT "Tenant_controllerPartitionId_fkey" FOREIGN KEY ("controllerPartitionId") REFERENCES "ControllerPartition"("id") ON DELETE SET NULL ON UPDATE SET NULL; - --- AddForeignKey -ALTER TABLE "Tenant" ADD CONSTRAINT "Tenant_workerPartitionId_fkey" FOREIGN KEY ("workerPartitionId") REFERENCES "TenantWorkerPartition"("id") ON DELETE SET NULL ON UPDATE SET NULL; diff --git a/prisma/migrations/20240701144845_v0_35_0/migration.sql b/prisma/migrations/20240701144845_v0_35_0/migration.sql deleted file mode 100644 index 08d93b198..000000000 --- a/prisma/migrations/20240701144845_v0_35_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "isPaused" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240703194644_v0_35_1/migration.sql b/prisma/migrations/20240703194644_v0_35_1/migration.sql deleted file mode 100644 index 194403abd..000000000 --- a/prisma/migrations/20240703194644_v0_35_1/migration.sql +++ /dev/null @@ -1,35 +0,0 @@ --- CreateIndex -CREATE INDEX "Event_tenantId_idx" ON "Event"("tenantId"); - --- CreateIndex -CREATE INDEX "Event_createdAt_idx" ON "Event"("createdAt"); - --- CreateIndex -CREATE INDEX "Event_tenantId_createdAt_idx" ON "Event"("tenantId", "createdAt"); - --- CreateIndex -CREATE INDEX "WorkflowRun_tenantId_idx" ON "WorkflowRun"("tenantId"); - --- CreateIndex -CREATE INDEX "WorkflowRun_workflowVersionId_idx" ON "WorkflowRun"("workflowVersionId"); - --- CreateIndex -CREATE INDEX "WorkflowRun_createdAt_idx" ON "WorkflowRun"("createdAt"); - --- CreateIndex -CREATE INDEX "WorkflowRun_tenantId_createdAt_idx" ON "WorkflowRun"("tenantId", "createdAt"); - --- CreateIndex -CREATE INDEX "WorkflowRun_finishedAt_idx" ON "WorkflowRun"("finishedAt"); - --- CreateIndex -CREATE INDEX "WorkflowRun_status_idx" ON "WorkflowRun"("status"); - --- CreateIndex -CREATE INDEX "WorkflowRunTriggeredBy_tenantId_idx" ON "WorkflowRunTriggeredBy"("tenantId"); - --- CreateIndex -CREATE INDEX "WorkflowRunTriggeredBy_eventId_idx" ON "WorkflowRunTriggeredBy"("eventId"); - --- CreateIndex -CREATE INDEX "WorkflowRunTriggeredBy_parentId_idx" ON "WorkflowRunTriggeredBy"("parentId"); diff --git a/prisma/migrations/20240704211308_v0_35_2/migration.sql b/prisma/migrations/20240704211308_v0_35_2/migration.sql deleted file mode 100644 index 3683f5d1e..000000000 --- a/prisma/migrations/20240704211308_v0_35_2/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Tenant" ADD COLUMN "dataRetentionPeriod" TEXT NOT NULL DEFAULT '720h'; diff --git a/prisma/migrations/20240712142938_v0_36_0/migration.sql b/prisma/migrations/20240712142938_v0_36_0/migration.sql deleted file mode 100644 index e8faafc53..000000000 --- a/prisma/migrations/20240712142938_v0_36_0/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ --- DropIndex -DROP INDEX "StepRun_tenantId_status_requeueAfter_createdAt_idx"; - --- CreateIndex -CREATE INDEX "StepRun_tenantId_idx" ON "StepRun"("tenantId"); - --- CreateIndex -CREATE INDEX "StepRun_workerId_idx" ON "StepRun"("workerId"); - --- CreateIndex -CREATE INDEX "StepRun_createdAt_idx" ON "StepRun"("createdAt"); - --- CreateIndex -CREATE INDEX "StepRun_jobRunId_status_tenantId_idx" ON "StepRun"("jobRunId", "status", "tenantId"); - --- CreateIndex -CREATE INDEX "StepRun_tenantId_status_timeoutAt_idx" ON "StepRun"("tenantId", "status", "timeoutAt"); diff --git a/prisma/migrations/20240715154325_v0_37_0/migration.sql b/prisma/migrations/20240715154325_v0_37_0/migration.sql deleted file mode 100644 index 8a988b4d0..000000000 --- a/prisma/migrations/20240715154325_v0_37_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "duration" INTEGER; diff --git a/prisma/migrations/20240716125848_v0_38_0/migration.sql b/prisma/migrations/20240716125848_v0_38_0/migration.sql deleted file mode 100644 index 75eecaa83..000000000 --- a/prisma/migrations/20240716125848_v0_38_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "APIToken" ADD COLUMN "internal" BOOLEAN NOT NULL DEFAULT false; diff --git a/prisma/migrations/20240716143342_v0_39_0/migration.sql b/prisma/migrations/20240716143342_v0_39_0/migration.sql deleted file mode 100644 index e2c85c5c9..000000000 --- a/prisma/migrations/20240716143342_v0_39_0/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ --- CreateIndex -CREATE INDEX "GetGroupKeyRun_deletedAt_idx" ON "GetGroupKeyRun"("deletedAt"); - --- CreateIndex -CREATE INDEX "JobRun_deletedAt_idx" ON "JobRun"("deletedAt"); - --- CreateIndex -CREATE INDEX "StepRun_deletedAt_idx" ON "StepRun"("deletedAt"); - --- CreateIndex -CREATE INDEX "Workflow_deletedAt_idx" ON "Workflow"("deletedAt"); - --- CreateIndex -CREATE INDEX "WorkflowRun_deletedAt_idx" ON "WorkflowRun"("deletedAt"); - --- CreateIndex -CREATE INDEX "WorkflowVersion_deletedAt_idx" ON "WorkflowVersion"("deletedAt"); diff --git a/prisma/migrations/20240726160621_v0_40_0/migration.sql b/prisma/migrations/20240726160621_v0_40_0/migration.sql deleted file mode 100644 index 43984f7b7..000000000 --- a/prisma/migrations/20240726160621_v0_40_0/migration.sql +++ /dev/null @@ -1,97 +0,0 @@ --- CreateEnum -CREATE TYPE "StickyStrategy" AS ENUM ('SOFT', 'HARD'); - --- CreateEnum -CREATE TYPE "WorkerLabelComparator" AS ENUM ('EQUAL', 'NOT_EQUAL', 'GREATER_THAN', 'GREATER_THAN_OR_EQUAL', 'LESS_THAN', 'LESS_THAN_OR_EQUAL'); - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "sticky" "StickyStrategy"; - --- CreateTable -CREATE TABLE "StepDesiredWorkerLabel" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "stepId" UUID NOT NULL, - "key" TEXT NOT NULL, - "strValue" TEXT, - "intValue" INTEGER, - "required" BOOLEAN NOT NULL, - "comparator" "WorkerLabelComparator" NOT NULL, - "weight" INTEGER NOT NULL, - - CONSTRAINT "StepDesiredWorkerLabel_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowRunStickyState" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "workflowRunId" UUID NOT NULL, - "desiredWorkerId" UUID, - "strategy" "StickyStrategy" NOT NULL, - - CONSTRAINT "WorkflowRunStickyState_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkflowRunDedupe" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "tenantId" UUID NOT NULL, - "workflowId" UUID NOT NULL, - "workflowRunId" UUID NOT NULL, - "value" TEXT NOT NULL -); - --- CreateTable -CREATE TABLE "WorkerLabel" ( - "id" BIGSERIAL NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "workerId" UUID NOT NULL, - "key" TEXT NOT NULL, - "strValue" TEXT, - "intValue" INTEGER, - - CONSTRAINT "WorkerLabel_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE INDEX "StepDesiredWorkerLabel_stepId_idx" ON "StepDesiredWorkerLabel"("stepId"); - --- CreateIndex -CREATE UNIQUE INDEX "StepDesiredWorkerLabel_stepId_key_key" ON "StepDesiredWorkerLabel"("stepId", "key"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunStickyState_workflowRunId_key" ON "WorkflowRunStickyState"("workflowRunId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunDedupe_id_key" ON "WorkflowRunDedupe"("id"); - --- CreateIndex -CREATE INDEX "WorkflowRunDedupe_tenantId_value_idx" ON "WorkflowRunDedupe"("tenantId", "value"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowRunDedupe_tenantId_workflowId_value_key" ON "WorkflowRunDedupe"("tenantId", "workflowId", "value"); - --- CreateIndex -CREATE INDEX "WorkerLabel_workerId_idx" ON "WorkerLabel"("workerId"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkerLabel_workerId_key_key" ON "WorkerLabel"("workerId", "key"); - --- AddForeignKey -ALTER TABLE "StepDesiredWorkerLabel" ADD CONSTRAINT "StepDesiredWorkerLabel_stepId_fkey" FOREIGN KEY ("stepId") REFERENCES "Step"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunStickyState" ADD CONSTRAINT "WorkflowRunStickyState_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "WorkflowRun"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkflowRunDedupe" ADD CONSTRAINT "WorkflowRunDedupe_tenantId_fkey" FOREIGN KEY ("tenantId") REFERENCES "Tenant"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkerLabel" ADD CONSTRAINT "WorkerLabel_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240728042304_v0_41_0/migration.sql b/prisma/migrations/20240728042304_v0_41_0/migration.sql deleted file mode 100644 index defa30154..000000000 --- a/prisma/migrations/20240728042304_v0_41_0/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- CreateEnum -CREATE TYPE "WorkflowKind" AS ENUM ('FUNCTION', 'DURABLE', 'DAG'); - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "kind" "WorkflowKind" NOT NULL DEFAULT 'DAG'; diff --git a/prisma/migrations/20240809130954_v0_42_0/migration.sql b/prisma/migrations/20240809130954_v0_42_0/migration.sql deleted file mode 100644 index de0325ce6..000000000 --- a/prisma/migrations/20240809130954_v0_42_0/migration.sql +++ /dev/null @@ -1,41 +0,0 @@ --- AlterEnum -ALTER TYPE "StepRunEventReason" ADD VALUE 'SENT_TO_WORKER'; - --- AlterEnum -ALTER TYPE "StepRunStatus" ADD VALUE 'CANCELLING'; - --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "queue" TEXT NOT NULL DEFAULT 'default'; - --- CreateTable -CREATE TABLE "Queue" ( - "id" BIGSERIAL NOT NULL, - "tenantId" UUID NOT NULL, - "name" TEXT NOT NULL, - - CONSTRAINT "Queue_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "QueueItem" ( - "id" BIGSERIAL NOT NULL, - "stepRunId" UUID, - "stepId" UUID, - "actionId" TEXT, - "scheduleTimeoutAt" TIMESTAMP(3), - "stepTimeout" TEXT, - "priority" INTEGER NOT NULL DEFAULT 1, - "isQueued" BOOLEAN NOT NULL, - "tenantId" UUID NOT NULL, - "queue" TEXT NOT NULL, - "sticky" "StickyStrategy", - "desiredWorkerId" UUID, - - CONSTRAINT "QueueItem_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "Queue_tenantId_name_key" ON "Queue"("tenantId", "name"); - --- CreateIndex -CREATE INDEX "QueueItem_isQueued_priority_tenantId_queue_id_idx" ON "QueueItem"("isQueued", "priority", "tenantId", "queue", "id"); diff --git a/prisma/migrations/20240815151145_v0_42_2/migration.sql b/prisma/migrations/20240815151145_v0_42_2/migration.sql deleted file mode 100644 index d49ad6add..000000000 --- a/prisma/migrations/20240815151145_v0_42_2/migration.sql +++ /dev/null @@ -1,20 +0,0 @@ --- CreateIndex -CREATE INDEX "GetGroupKeyRun_tenantId_idx" ON "GetGroupKeyRun"("tenantId"); - --- CreateIndex -CREATE INDEX "GetGroupKeyRun_workerId_idx" ON "GetGroupKeyRun"("workerId"); - --- CreateIndex -CREATE INDEX "GetGroupKeyRun_createdAt_idx" ON "GetGroupKeyRun"("createdAt"); - --- CreateIndex -CREATE INDEX "GetGroupKeyRun_tenantId_deletedAt_status_idx" ON "GetGroupKeyRun"("tenantId", "deletedAt", "status"); - --- CreateIndex -CREATE INDEX "GetGroupKeyRun_status_deletedAt_timeoutAt_idx" ON "GetGroupKeyRun"("status", "deletedAt", "timeoutAt"); - -DROP INDEX IF EXISTS "QueueItem_isQueued_priority_tenantId_queue_id_idx"; - --- CreateIndex -CREATE INDEX IF NOT EXISTS "QueueItem_isQueued_priority_tenantId_queue_id_idx_2" ON "QueueItem" ("isQueued", "tenantId", "queue", "priority" DESC, "id"); - diff --git a/prisma/migrations/20240820201021_0_42_3/migration.sql b/prisma/migrations/20240820201021_0_42_3/migration.sql deleted file mode 100644 index c9c8f9055..000000000 --- a/prisma/migrations/20240820201021_0_42_3/migration.sql +++ /dev/null @@ -1,19 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[actionId,tenantId]` on the table `Action` will be added. If there are existing duplicate values, this will fail. - - A unique constraint covering the columns `[webhookId]` on the table `Worker` will be added. If there are existing duplicate values, this will fail. - -*/ --- CreateEnum -CREATE TYPE "WorkerType" AS ENUM ('WEBHOOK', 'MANAGED', 'SELFHOSTED'); - --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "type" "WorkerType" NOT NULL DEFAULT 'SELFHOSTED', -ADD COLUMN "webhookId" UUID; - --- CreateIndex -CREATE UNIQUE INDEX "Worker_webhookId_key" ON "Worker"("webhookId"); - --- AddForeignKey -ALTER TABLE "Worker" ADD CONSTRAINT "Worker_webhookId_fkey" FOREIGN KEY ("webhookId") REFERENCES "WebhookWorker"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20240823120423_0_42_4/migration.sql b/prisma/migrations/20240823120423_0_42_4/migration.sql deleted file mode 100644 index 4ee9700ac..000000000 --- a/prisma/migrations/20240823120423_0_42_4/migration.sql +++ /dev/null @@ -1,19 +0,0 @@ --- CreateEnum -CREATE TYPE "WebhookWorkerRequestMethod" AS ENUM ('GET', 'POST', 'PUT'); - --- CreateTable -CREATE TABLE "WebhookWorkerRequest" ( - "id" UUID NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "webhookWorkerId" UUID NOT NULL, - "method" "WebhookWorkerRequestMethod" NOT NULL, - "statusCode" INTEGER NOT NULL, - - CONSTRAINT "WebhookWorkerRequest_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "WebhookWorkerRequest_id_key" ON "WebhookWorkerRequest"("id"); - --- AddForeignKey -ALTER TABLE "WebhookWorkerRequest" ADD CONSTRAINT "WebhookWorkerRequest_webhookWorkerId_fkey" FOREIGN KEY ("webhookWorkerId") REFERENCES "WebhookWorker"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240823204116_0_42_5/migration.sql b/prisma/migrations/20240823204116_0_42_5/migration.sql deleted file mode 100644 index b1298aeee..000000000 --- a/prisma/migrations/20240823204116_0_42_5/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "priority" INTEGER; - --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "priority" INTEGER; - --- AlterTable -ALTER TABLE "WorkflowVersion" ADD COLUMN "defaultPriority" INTEGER; diff --git a/prisma/migrations/20240829142541_v0_43_2/migration.sql b/prisma/migrations/20240829142541_v0_43_2/migration.sql deleted file mode 100644 index 692e38991..000000000 --- a/prisma/migrations/20240829142541_v0_43_2/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterTable -ALTER TABLE "ControllerPartition" ADD COLUMN "name" TEXT; - --- AlterTable -ALTER TABLE "TenantWorkerPartition" ADD COLUMN "name" TEXT; diff --git a/prisma/migrations/20240904120320_v0_44_0/migration.sql b/prisma/migrations/20240904120320_v0_44_0/migration.sql deleted file mode 100644 index a83dd34bd..000000000 --- a/prisma/migrations/20240904120320_v0_44_0/migration.sql +++ /dev/null @@ -1,53 +0,0 @@ --- CreateEnum -CREATE TYPE "InternalQueue" AS ENUM ('WORKER_SEMAPHORE_COUNT', 'STEP_RUN_UPDATE'); - --- CreateTable -CREATE TABLE "InternalQueueItem" ( - "id" BIGSERIAL NOT NULL, - "queue" "InternalQueue" NOT NULL, - "isQueued" BOOLEAN NOT NULL, - "data" JSONB, - "tenantId" UUID NOT NULL, - "priority" INTEGER NOT NULL DEFAULT 1, - "uniqueKey" TEXT, - - CONSTRAINT "InternalQueueItem_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "WorkerSemaphoreCount" ( - "workerId" UUID NOT NULL, - "count" INTEGER NOT NULL, - - CONSTRAINT "WorkerSemaphoreCount_pkey" PRIMARY KEY ("workerId") -); - --- CreateTable -CREATE TABLE "WorkerAssignEvent" ( - "id" BIGSERIAL NOT NULL, - "workerId" UUID NOT NULL, - "assignedStepRuns" JSONB, - - CONSTRAINT "WorkerAssignEvent_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE INDEX "InternalQueueItem_isQueued_tenantId_queue_priority_id_idx" ON "InternalQueueItem"("isQueued", "tenantId", "queue", "priority" DESC, "id"); - --- CreateIndex -CREATE UNIQUE INDEX "InternalQueueItem_tenantId_queue_uniqueKey_key" ON "InternalQueueItem"("tenantId", "queue", "uniqueKey"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkerSemaphoreCount_workerId_key" ON "WorkerSemaphoreCount"("workerId"); - --- CreateIndex -CREATE INDEX "WorkerSemaphoreCount_workerId_idx" ON "WorkerSemaphoreCount"("workerId"); - --- CreateIndex -CREATE INDEX "WorkerAssignEvent_workerId_id_idx" ON "WorkerAssignEvent"("workerId", "id"); - --- AddForeignKey -ALTER TABLE "WorkerSemaphoreCount" ADD CONSTRAINT "WorkerSemaphoreCount_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "WorkerAssignEvent" ADD CONSTRAINT "WorkerAssignEvent_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20240910201520_v0_44_5/migration.sql b/prisma/migrations/20240910201520_v0_44_5/migration.sql deleted file mode 100644 index 6a1da99fb..000000000 --- a/prisma/migrations/20240910201520_v0_44_5/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ --- CreateTable -CREATE TABLE "TimeoutQueueItem" ( - "id" BIGSERIAL NOT NULL, - "stepRunId" UUID NOT NULL, - "retryCount" INTEGER NOT NULL, - "timeoutAt" TIMESTAMP(3) NOT NULL, - "tenantId" UUID NOT NULL, - "isQueued" BOOLEAN NOT NULL, - - CONSTRAINT "TimeoutQueueItem_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE INDEX "TimeoutQueueItem_tenantId_isQueued_timeoutAt_idx" ON "TimeoutQueueItem"("tenantId", "isQueued", "timeoutAt"); - --- CreateIndex -CREATE UNIQUE INDEX "TimeoutQueueItem_stepRunId_retryCount_key" ON "TimeoutQueueItem"("stepRunId", "retryCount"); diff --git a/prisma/migrations/20240911124010_v0_44_6/migration.sql b/prisma/migrations/20240911124010_v0_44_6/migration.sql deleted file mode 100644 index 756ae9b9b..000000000 --- a/prisma/migrations/20240911124010_v0_44_6/migration.sql +++ /dev/null @@ -1,15 +0,0 @@ --- CreateTable -CREATE TABLE "SemaphoreQueueItem" ( - "id" BIGSERIAL NOT NULL, - "stepRunId" UUID NOT NULL, - "workerId" UUID NOT NULL, - "tenantId" UUID NOT NULL, - - CONSTRAINT "SemaphoreQueueItem_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE INDEX "SemaphoreQueueItem_tenantId_workerId_idx" ON "SemaphoreQueueItem"("tenantId", "workerId"); - --- CreateIndex -CREATE UNIQUE INDEX "SemaphoreQueueItem_stepRunId_workerId_key" ON "SemaphoreQueueItem"("stepRunId", "workerId"); diff --git a/prisma/migrations/20240911201824_v0_44_7/migration.sql b/prisma/migrations/20240911201824_v0_44_7/migration.sql deleted file mode 100644 index 131216552..000000000 --- a/prisma/migrations/20240911201824_v0_44_7/migration.sql +++ /dev/null @@ -1,28 +0,0 @@ -/* - Warnings: - - - You are about to drop the `WorkerSemaphore` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `WorkerSemaphoreCount` table. If the table is not empty, all the data it contains will be lost. - - You are about to drop the `WorkerSemaphoreSlot` table. If the table is not empty, all the data it contains will be lost. - -*/ --- DropForeignKey -ALTER TABLE "WorkerSemaphore" DROP CONSTRAINT "WorkerSemaphore_workerId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkerSemaphoreCount" DROP CONSTRAINT "WorkerSemaphoreCount_workerId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkerSemaphoreSlot" DROP CONSTRAINT "WorkerSemaphoreSlot_stepRunId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkerSemaphoreSlot" DROP CONSTRAINT "WorkerSemaphoreSlot_workerId_fkey"; - --- DropTable -DROP TABLE "WorkerSemaphore"; - --- DropTable -DROP TABLE "WorkerSemaphoreCount"; - --- DropTable -DROP TABLE "WorkerSemaphoreSlot"; diff --git a/prisma/migrations/20240916121446_v0_44_8/migration.sql b/prisma/migrations/20240916121446_v0_44_8/migration.sql deleted file mode 100644 index ab79e0d45..000000000 --- a/prisma/migrations/20240916121446_v0_44_8/migration.sql +++ /dev/null @@ -1,27 +0,0 @@ -/* - Warnings: - - - The primary key for the `SemaphoreQueueItem` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `id` on the `SemaphoreQueueItem` table. All the data in the column will be lost. - - A unique constraint covering the columns `[stepRunId]` on the table `SemaphoreQueueItem` will be added. If there are existing duplicate values, this will fail. - -*/ --- DropIndex -DROP INDEX "SemaphoreQueueItem_stepRunId_workerId_key"; - --- DropIndex -DROP INDEX "StepRun_jobRunId_status_tenantId_idx"; - --- DropIndex -DROP INDEX "StepRun_tenantId_status_timeoutAt_idx"; - --- AlterTable -ALTER TABLE "SemaphoreQueueItem" DROP CONSTRAINT "SemaphoreQueueItem_pkey", -DROP COLUMN "id", -ADD CONSTRAINT "SemaphoreQueueItem_pkey" PRIMARY KEY ("stepRunId"); - --- AlterTable -ALTER TABLE "StepRunResultArchive" ADD COLUMN "retryCount" INTEGER NOT NULL DEFAULT 0; - --- CreateIndex -CREATE UNIQUE INDEX "SemaphoreQueueItem_stepRunId_key" ON "SemaphoreQueueItem"("stepRunId"); diff --git a/prisma/migrations/20240918162525_v0_45_0/migration.sql b/prisma/migrations/20240918162525_v0_45_0/migration.sql deleted file mode 100644 index 125e18399..000000000 --- a/prisma/migrations/20240918162525_v0_45_0/migration.sql +++ /dev/null @@ -1,26 +0,0 @@ --- AlterEnum -ALTER TYPE "InternalQueue" ADD VALUE 'WORKFLOW_RUN_UPDATE'; - --- AlterEnum --- This migration adds more than one value to an enum. --- With PostgreSQL versions 11 and earlier, this is not possible --- in a single migration. This can be worked around by creating --- multiple migrations, each migration adding only one value to --- the enum. - - -ALTER TYPE "StepRunEventReason" ADD VALUE 'WORKFLOW_RUN_GROUP_KEY_SUCCEEDED'; -ALTER TYPE "StepRunEventReason" ADD VALUE 'WORKFLOW_RUN_GROUP_KEY_FAILED'; - --- DropForeignKey -ALTER TABLE "StepRunEvent" DROP CONSTRAINT "StepRunEvent_stepRunId_fkey"; - --- AlterTable -ALTER TABLE "StepRunEvent" ADD COLUMN "workflowRunId" UUID, -ALTER COLUMN "stepRunId" DROP NOT NULL; - --- AlterTable -ALTER TABLE "WorkflowConcurrency" ADD COLUMN "concurrencyGroupExpression" TEXT; - --- CreateIndex -CREATE INDEX "StepRunEvent_workflowRunId_idx" ON "StepRunEvent"("workflowRunId"); diff --git a/prisma/migrations/20240923124800_v0_45_4/migration.sql b/prisma/migrations/20240923124800_v0_45_4/migration.sql deleted file mode 100644 index 60a55817c..000000000 --- a/prisma/migrations/20240923124800_v0_45_4/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "WorkflowRun" ALTER COLUMN "duration" SET DATA TYPE BIGINT; diff --git a/prisma/migrations/20240926210641_v0_47_0/migration.sql b/prisma/migrations/20240926210641_v0_47_0/migration.sql deleted file mode 100644 index c77a7ecb8..000000000 --- a/prisma/migrations/20240926210641_v0_47_0/migration.sql +++ /dev/null @@ -1,35 +0,0 @@ --- CreateEnum -CREATE TYPE "StepRateLimitKind" AS ENUM ('STATIC', 'DYNAMIC'); - --- CreateEnum -CREATE TYPE "StepExpressionKind" AS ENUM ('DYNAMIC_RATE_LIMIT_KEY', 'DYNAMIC_RATE_LIMIT_VALUE', 'DYNAMIC_RATE_LIMIT_UNITS', 'DYNAMIC_RATE_LIMIT_WINDOW'); - --- AlterEnum -ALTER TYPE "StepRunEventReason" ADD VALUE 'RATE_LIMIT_ERROR'; - --- DropForeignKey -ALTER TABLE "StepRateLimit" DROP CONSTRAINT "StepRateLimit_stepId_fkey"; - --- AlterTable -ALTER TABLE "StepRateLimit" ADD COLUMN "kind" "StepRateLimitKind" NOT NULL DEFAULT 'STATIC'; - --- CreateTable -CREATE TABLE "StepExpression" ( - "key" TEXT NOT NULL, - "stepId" UUID NOT NULL, - "expression" TEXT NOT NULL, - "kind" "StepExpressionKind" NOT NULL, - - CONSTRAINT "StepExpression_pkey" PRIMARY KEY ("key","stepId","kind") -); - --- CreateTable -CREATE TABLE "StepRunExpressionEval" ( - "key" TEXT NOT NULL, - "stepRunId" UUID NOT NULL, - "valueStr" TEXT, - "valueInt" INTEGER, - "kind" "StepExpressionKind" NOT NULL, - - CONSTRAINT "StepRunExpressionEval_pkey" PRIMARY KEY ("key","stepRunId","kind") -); diff --git a/prisma/migrations/20240927172926_v0_47_1/migration.sql b/prisma/migrations/20240927172926_v0_47_1/migration.sql deleted file mode 100644 index fda36bc21..000000000 --- a/prisma/migrations/20240927172926_v0_47_1/migration.sql +++ /dev/null @@ -1,65 +0,0 @@ --- DropForeignKey -ALTER TABLE "Event" DROP CONSTRAINT "Event_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "GetGroupKeyRun" DROP CONSTRAINT "GetGroupKeyRun_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "Job" DROP CONSTRAINT "Job_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "JobRun" DROP CONSTRAINT "JobRun_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "JobRun" DROP CONSTRAINT "JobRun_tickerId_fkey"; - --- DropForeignKey -ALTER TABLE "LogLine" DROP CONSTRAINT "LogLine_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "RateLimit" DROP CONSTRAINT "RateLimit_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "Step" DROP CONSTRAINT "Step_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "StepRateLimit" DROP CONSTRAINT "StepRateLimit_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "StepRun" DROP CONSTRAINT "StepRun_stepId_fkey"; - --- DropForeignKey -ALTER TABLE "StepRun" DROP CONSTRAINT "StepRun_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "StepRun" DROP CONSTRAINT "StepRun_tickerId_fkey"; - --- DropForeignKey -ALTER TABLE "StreamEvent" DROP CONSTRAINT "StreamEvent_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "Worker" DROP CONSTRAINT "Worker_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "Workflow" DROP CONSTRAINT "Workflow_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRun" DROP CONSTRAINT "WorkflowRun_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRun" DROP CONSTRAINT "WorkflowRun_workflowVersionId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRunDedupe" DROP CONSTRAINT "WorkflowRunDedupe_tenantId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" DROP CONSTRAINT "WorkflowRunTriggeredBy_eventId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" DROP CONSTRAINT "WorkflowRunTriggeredBy_parentId_fkey"; - --- DropForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" DROP CONSTRAINT "WorkflowRunTriggeredBy_tenantId_fkey"; - --- CreateIndex -CREATE INDEX "StepRunExpressionEval_stepRunId_idx" ON "StepRunExpressionEval"("stepRunId"); diff --git a/prisma/migrations/20240928144309_v0_48_0/migration.sql b/prisma/migrations/20240928144309_v0_48_0/migration.sql deleted file mode 100644 index 6be078a30..000000000 --- a/prisma/migrations/20240928144309_v0_48_0/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterEnum -ALTER TYPE "InternalQueue" ADD VALUE 'WORKFLOW_RUN_PAUSED'; - --- AlterTable -ALTER TABLE "Workflow" ADD COLUMN "isPaused" BOOLEAN DEFAULT false; diff --git a/prisma/migrations/20240930202651_v0_48_1/migration.sql b/prisma/migrations/20240930202651_v0_48_1/migration.sql deleted file mode 100644 index 3162f891b..000000000 --- a/prisma/migrations/20240930202651_v0_48_1/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- DropForeignKey -ALTER TABLE "JobRun" DROP CONSTRAINT "JobRun_jobId_fkey"; - --- DropForeignKey -ALTER TABLE "JobRunLookupData" DROP CONSTRAINT "JobRunLookupData_tenantId_fkey"; diff --git a/prisma/migrations/20241002174554_0_48_2/migration.sql b/prisma/migrations/20241002174554_0_48_2/migration.sql deleted file mode 100644 index 67849da7a..000000000 --- a/prisma/migrations/20241002174554_0_48_2/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterEnum -ALTER TYPE "StepRunEventReason" ADD VALUE 'ACKNOWLEDGED'; diff --git a/prisma/migrations/20241003135009_v0_49_0/migration.sql b/prisma/migrations/20241003135009_v0_49_0/migration.sql deleted file mode 100644 index 71a9aabdb..000000000 --- a/prisma/migrations/20241003135009_v0_49_0/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "Event" ADD COLUMN "insertOrder" INTEGER; diff --git a/prisma/migrations/20241004122152_v0_49_1/migration.sql b/prisma/migrations/20241004122152_v0_49_1/migration.sql deleted file mode 100644 index ec909e885..000000000 --- a/prisma/migrations/20241004122152_v0_49_1/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterEnum -ALTER TYPE "InternalQueue" ADD VALUE 'STEP_RUN_UPDATE_V2'; diff --git a/prisma/migrations/20241008124029_v0_49_2/migration.sql b/prisma/migrations/20241008124029_v0_49_2/migration.sql deleted file mode 100644 index 0d238caeb..000000000 --- a/prisma/migrations/20241008124029_v0_49_2/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ --- CreateTable -CREATE TABLE "EventKey" ( - "key" TEXT NOT NULL, - "tenantId" UUID NOT NULL, - - CONSTRAINT "EventKey_pkey" PRIMARY KEY ("key") -); - --- CreateIndex -CREATE UNIQUE INDEX "EventKey_key_tenantId_key" ON "EventKey"("key", "tenantId"); diff --git a/prisma/migrations/20241011205303_0_49_3/migration.sql b/prisma/migrations/20241011205303_0_49_3/migration.sql deleted file mode 100644 index 0920a72db..000000000 --- a/prisma/migrations/20241011205303_0_49_3/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* - Warnings: - - - The primary key for the `EventKey` table will be changed. If it partially fails, the table could be left without primary key constraint. - -*/ --- AlterTable -ALTER TABLE "EventKey" DROP CONSTRAINT "EventKey_pkey", -ADD COLUMN "id" BIGSERIAL NOT NULL, -ADD CONSTRAINT "EventKey_pkey" PRIMARY KEY ("id"); diff --git a/prisma/migrations/20241014194315_v0_50_0/migration.sql b/prisma/migrations/20241014194315_v0_50_0/migration.sql deleted file mode 100644 index fa49b6c42..000000000 --- a/prisma/migrations/20241014194315_v0_50_0/migration.sql +++ /dev/null @@ -1,29 +0,0 @@ --- CreateEnum -CREATE TYPE "LeaseKind" AS ENUM ('WORKER', 'QUEUE'); - --- AlterTable -ALTER TABLE "WorkflowRun" ADD COLUMN "insertOrder" INTEGER; - --- CreateTable -CREATE TABLE "Lease" ( - "id" BIGSERIAL NOT NULL, - "expiresAt" TIMESTAMP(3), - "tenantId" UUID NOT NULL, - "resourceId" TEXT NOT NULL, - "kind" "LeaseKind" NOT NULL, - - CONSTRAINT "Lease_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "Lease_tenantId_kind_resourceId_key" ON "Lease"("tenantId", "kind", "resourceId"); - --- CreateEnum -CREATE TYPE "WorkerSDKS" AS ENUM ('UNKNOWN', 'GO', 'PYTHON', 'TYPESCRIPT'); - --- AlterTable -ALTER TABLE "Worker" ADD COLUMN "language" "WorkerSDKS", -ADD COLUMN "languageVersion" TEXT, -ADD COLUMN "os" TEXT, -ADD COLUMN "runtimeExtra" TEXT, -ADD COLUMN "sdkVersion" TEXT; diff --git a/prisma/migrations/20241022124201_v0_50_2/migration.sql b/prisma/migrations/20241022124201_v0_50_2/migration.sql deleted file mode 100644 index 85b10f0f7..000000000 --- a/prisma/migrations/20241022124201_v0_50_2/migration.sql +++ /dev/null @@ -1,19 +0,0 @@ --- AlterTable -ALTER TABLE "Tenant" ADD COLUMN "schedulerPartitionId" TEXT; - --- CreateTable -CREATE TABLE "SchedulerPartition" ( - "id" TEXT NOT NULL, - "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "lastHeartbeat" TIMESTAMP(3), - "name" TEXT, - - CONSTRAINT "SchedulerPartition_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "SchedulerPartition_id_key" ON "SchedulerPartition"("id"); - --- AddForeignKey -ALTER TABLE "Tenant" ADD CONSTRAINT "Tenant_schedulerPartitionId_fkey" FOREIGN KEY ("schedulerPartitionId") REFERENCES "SchedulerPartition"("id") ON DELETE SET NULL ON UPDATE SET NULL; diff --git a/prisma/migrations/20241023112223_v0_50_3/migration.sql b/prisma/migrations/20241023112223_v0_50_3/migration.sql deleted file mode 100644 index 34da6da81..000000000 --- a/prisma/migrations/20241023112223_v0_50_3/migration.sql +++ /dev/null @@ -1,5 +0,0 @@ --- AlterTable -ALTER TABLE "Queue" ADD COLUMN "lastActive" TIMESTAMP(3); - --- CreateIndex -CREATE INDEX "Queue_tenantId_lastActive_idx" ON "Queue"("tenantId", "lastActive"); diff --git a/prisma/migrations/20241029122618_v0_51_0/migration.sql b/prisma/migrations/20241029122618_v0_51_0/migration.sql deleted file mode 100644 index 39b1dcfa1..000000000 --- a/prisma/migrations/20241029122618_v0_51_0/migration.sql +++ /dev/null @@ -1,11 +0,0 @@ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "additionalMetadata" JSONB, -ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, -ADD COLUMN "deletedAt" TIMESTAMP(3), -ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; - --- AlterTable -ALTER TABLE "WorkflowTriggerScheduledRef" ADD COLUMN "additionalMetadata" JSONB, -ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, -ADD COLUMN "deletedAt" TIMESTAMP(3), -ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/prisma/migrations/20241030131339_tmp/migration.sql b/prisma/migrations/20241030131339_tmp/migration.sql deleted file mode 100644 index e994d5f0b..000000000 --- a/prisma/migrations/20241030131339_tmp/migration.sql +++ /dev/null @@ -1,23 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[parentId,cron,name]` on the table `WorkflowTriggerCronRef` will be added. If there are existing duplicate values, this will fail. - - The required column `id` was added to the `WorkflowTriggerCronRef` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required. - -*/ --- DropForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" DROP CONSTRAINT "WorkflowRunTriggeredBy_cronParentId_cronSchedule_fkey"; - --- AlterTable -ALTER TABLE "WorkflowRunTriggeredBy" ADD COLUMN "cronName" TEXT; - --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "id" UUID NOT NULL, -ADD COLUMN "name" TEXT, -ADD CONSTRAINT "WorkflowTriggerCronRef_pkey" PRIMARY KEY ("id"); - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerCronRef_parentId_cron_name_key" ON "WorkflowTriggerCronRef"("parentId", "cron", "name"); - --- AddForeignKey -ALTER TABLE "WorkflowRunTriggeredBy" ADD CONSTRAINT "WorkflowRunTriggeredBy_cronParentId_cronSchedule_cronName_fkey" FOREIGN KEY ("cronParentId", "cronSchedule", "cronName") REFERENCES "WorkflowTriggerCronRef"("parentId", "cron", "name") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20241030133040_tmp/migration.sql b/prisma/migrations/20241030133040_tmp/migration.sql deleted file mode 100644 index 1465f196e..000000000 --- a/prisma/migrations/20241030133040_tmp/migration.sql +++ /dev/null @@ -1,10 +0,0 @@ -/* - Warnings: - - - The primary key for the `WorkflowTriggerCronRef` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `id` on the `WorkflowTriggerCronRef` table. All the data in the column will be lost. - -*/ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" DROP CONSTRAINT "WorkflowTriggerCronRef_pkey", -DROP COLUMN "id"; diff --git a/prisma/migrations/20241030150107_tmp/migration.sql b/prisma/migrations/20241030150107_tmp/migration.sql deleted file mode 100644 index 67a1cef29..000000000 --- a/prisma/migrations/20241030150107_tmp/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - A unique constraint covering the columns `[id]` on the table `WorkflowTriggerCronRef` will be added. If there are existing duplicate values, this will fail. - - The required column `id` was added to the `WorkflowTriggerCronRef` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required. - -*/ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "id" UUID NOT NULL; - --- CreateIndex -CREATE UNIQUE INDEX "WorkflowTriggerCronRef_id_key" ON "WorkflowTriggerCronRef"("id"); diff --git a/prisma/migrations/20241104202817_tmp/migration.sql b/prisma/migrations/20241104202817_tmp/migration.sql deleted file mode 100644 index a64493312..000000000 --- a/prisma/migrations/20241104202817_tmp/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- DropIndex -DROP INDEX "WorkflowTriggerCronRef_parentId_cron_key"; diff --git a/prisma/migrations/20241107162929_v0_51_2/migration.sql b/prisma/migrations/20241107162929_v0_51_2/migration.sql deleted file mode 100644 index d10d394bd..000000000 --- a/prisma/migrations/20241107162929_v0_51_2/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "StepRun" ADD COLUMN "internalRetryCount" INTEGER NOT NULL DEFAULT 0; diff --git a/prisma/migrations/20241114175339_v0_51_3/migration.sql b/prisma/migrations/20241114175339_v0_51_3/migration.sql deleted file mode 100644 index 67b851e5f..000000000 --- a/prisma/migrations/20241114175339_v0_51_3/migration.sql +++ /dev/null @@ -1,3 +0,0 @@ --- AlterTable -ALTER TABLE "Event" ALTER COLUMN "createdAt" SET DEFAULT CLOCK_TIMESTAMP(), -ALTER COLUMN "createdAt" SET DATA TYPE TIMESTAMP(6); diff --git a/prisma/migrations/20241120193249_tmp/migration.sql b/prisma/migrations/20241120193249_tmp/migration.sql deleted file mode 100644 index 4367df84e..000000000 --- a/prisma/migrations/20241120193249_tmp/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ALTER COLUMN "parentId" DROP NOT NULL; diff --git a/prisma/migrations/20241120193948_tmp/migration.sql b/prisma/migrations/20241120193948_tmp/migration.sql deleted file mode 100644 index 54c03bd34..000000000 --- a/prisma/migrations/20241120193948_tmp/migration.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - Warnings: - - - Made the column `parentId` on table `WorkflowTriggerCronRef` required. This step will fail if there are existing NULL values in that column. - -*/ --- AlterTable -ALTER TABLE "WorkflowTriggerCronRef" ALTER COLUMN "parentId" SET NOT NULL; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml deleted file mode 100644 index 99e4f2009..000000000 --- a/prisma/migrations/migration_lock.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Please do not edit this file manually -# It should be added in your version-control system (i.e. Git) -provider = "postgresql" diff --git a/sql/migrations/20241121142159_v0.52.0.sql b/sql/migrations/20241121142159_v0.52.0.sql index 64acc3de5..6b120eaf3 100644 --- a/sql/migrations/20241121142159_v0.52.0.sql +++ b/sql/migrations/20241121142159_v0.52.0.sql @@ -1,10 +1,16 @@ -- atlas:txmode none - - --- 'Creating an updatedAt index that will be useful later'; create index CONCURRENTLY IF NOT EXISTS "StepRun_updatedAt_idx" on "StepRun" ("updatedAt"); + -- 'Created index'; +-- print the time +DO $$ +BEGIN + RAISE NOTICE 'Starting at time=%', clock_timestamp(); +END $$; + +BEGIN TRANSACTION; + DO $$ DECLARE retry_count INT := 0; @@ -13,49 +19,25 @@ DECLARE rec RECORD; sql_statement TEXT; newest_record RECORD; + start_time TIMESTAMP; + end_time TIMESTAMP; BEGIN - SET LOCAL lock_timeout = '30s'; - - - CREATE TABLE "StepRun_new" ( - "id" uuid NOT NULL, - "createdAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, - "deletedAt" timestamp(3), - "tenantId" uuid NOT NULL, - "jobRunId" uuid NOT NULL, - "stepId" uuid NOT NULL, - "order" BIGSERIAL, - "workerId" uuid, - "tickerId" uuid, - "status" "StepRunStatus" NOT NULL DEFAULT 'PENDING'::"StepRunStatus", - "input" jsonb, - "output" jsonb, - "requeueAfter" timestamp(3) without time zone, - "scheduleTimeoutAt" timestamp(3) without time zone, - "error" text, - "startedAt" timestamp(3) without time zone, - "finishedAt" timestamp(3) without time zone, - "timeoutAt" timestamp(3) without time zone, - "cancelledAt" timestamp(3) without time zone, - "cancelledReason" text, - "cancelledError" text, - "inputSchema" jsonb, - "callerFiles" jsonb, - "gitRepoBranch" text, - "retryCount" integer NOT NULL DEFAULT 0, - "semaphoreReleased" boolean NOT NULL DEFAULT false, - "queue" text NOT NULL DEFAULT 'default'::text, - "priority" integer, - "internalRetryCount" INTEGER NOT NULL DEFAULT 0, - "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, - - PRIMARY KEY ( "status", "id"), - UNIQUE ("status", "identityId") - - ) PARTITION BY LIST ("status"); + SET LOCAL lock_timeout = '25s'; + SET LOCAL statement_timeout = '0'; + + + + CREATE TABLE "StepRun_new" ( LIKE "StepRun" INCLUDING DEFAULTS, "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, + PRIMARY KEY ( "status", "id"), + UNIQUE ("status", "identityId") ) + PARTITION BY LIST ("status"); + + + + + RAISE NOTICE 'Created table "StepRun_new"'; @@ -104,26 +86,34 @@ BEGIN CREATE INDEX "StepRun_workerId_idx" ON "StepRun_new" ("workerId"); CREATE INDEX "StepRun_status_tenantId_idx" ON "StepRun_new" ("status", "tenantId"); + -- Create index "StepRun_id_key" to table: "StepRun" CREATE UNIQUE INDEX IF NOT EXISTS "StepRun_new_id_key" ON "StepRun_new" ("id", "status"); -- Create index "StepRun_jobRunId_status_tenantId_idx" to table: "StepRun" CREATE INDEX IF NOT EXISTS "StepRun_new_jobRunId_status_tenantId_idx" ON "StepRun_new" ("jobRunId", "status", "tenantId") WHERE (status = 'PENDING'::"StepRunStatus"); RAISE NOTICE 'Created indexes for "StepRun_new"'; - + RAISE NOTICE 'Creating identity constraint for "StepRun_new"'; + ALTER TABLE "StepRun_new" + ADD CONSTRAINT "StepRun_new_identityId_status_unique" UNIQUE ("identityId","status"); + RAISE NOTICE 'Created identity constraint for "StepRun_new"'; RAISE NOTICE 'StepRun_new table created successfully now we try and swap the tables'; - WHILE retry_count < max_retries LOOP + WHILE retry_count < max_retries + LOOP BEGIN - + SET LOCAL lock_timeout = '25s'; + SET LOCAL statement_timeout = '0'; RAISE NOTICE 'Checking for data since the last select'; - INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( + INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" = (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" ); + + INSERT INTO "StepRun_new" SELECT * FROM "StepRun" where "updatedAt" > (SELECT max("updatedAt") FROM "StepRun_new") ; ALTER TABLE "StepRun_volatile" SET (autovacuum_vacuum_threshold = '1000', autovacuum_vacuum_scale_factor = '0.01', @@ -132,31 +122,42 @@ CREATE INDEX IF NOT EXISTS "StepRun_new_jobRunId_status_tenantId_idx" ON "StepRu RAISE NOTICE 'Renaming tables and copying any new data'; + BEGIN - LOCK TABLE "StepRun" IN ACCESS EXCLUSIVE MODE; + SET LOCAL lock_timeout = '10s'; + SET LOCAL statement_timeout = '0'; + RAISE NOTICE 'Acquiring locks on dependent tables'; + start_time := clock_timestamp(); + LOCK TABLE "StepRun" IN ACCESS EXCLUSIVE MODE; + end_time := clock_timestamp(); + RAISE NOTICE 'Acquired StepRun lock in % ms', EXTRACT(MILLISECOND FROM end_time - start_time); - LOCK TABLE "_StepRunOrder" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "StepRunResultArchive" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "LogLine" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "WorkflowTriggerScheduledRef" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "WorkflowRun" IN ACCESS EXCLUSIVE MODE; - LOCK TABLE "StreamEvent" IN ACCESS EXCLUSIVE MODE; + RAISE NOTICE 'Acquired locks on dependent tables'; + - INSERT INTO "StepRun_new" SELECT * FROM "StepRun" - WHERE "updatedAt" >= (SELECT max("updatedAt") FROM "StepRun_new") + WHERE "updatedAt" = (SELECT max("updatedAt") FROM "StepRun_new") AND NOT EXISTS ( SELECT 1 FROM "StepRun_new" WHERE "StepRun_new"."id" = "StepRun"."id" ); + RAISE NOTICE 'Inserted data with the same updatedAt'; + -- only need to check for equality on the updatedAt column greater than should be fine + INSERT INTO "StepRun_new" + SELECT * + FROM "StepRun" + WHERE "updatedAt" > (SELECT max("updatedAt") FROM "StepRun_new"); + + + RAISE NOTICE 'Inserted data with a greater updatedAt'; ALTER TABLE "StepRun" RENAME TO "StepRun_old"; @@ -164,133 +165,1012 @@ CREATE INDEX IF NOT EXISTS "StepRun_new_jobRunId_status_tenantId_idx" ON "StepRu RAISE NOTICE 'Renamed tables now we try and create the triggers'; - FOR rec IN - SELECT - conname AS constraint_name, - conrelid::regclass AS referencing_table, - a.attname AS referencing_column, - confrelid::regclass AS referenced_table, - af.attname AS referenced_column - FROM - pg_constraint c - JOIN - pg_attribute a ON a.attnum = ANY(c.conkey) AND a.attrelid = c.conrelid - JOIN - pg_attribute af ON af.attnum = ANY(c.confkey) AND af.attrelid = c.confrelid - WHERE - confrelid = '"StepRun_old"'::regclass - AND contype = 'f' - LOOP - - RAISE NOTICE 'Referencing column: %, Referenced table: %, Referenced column: %', rec.referencing_column, rec.referenced_table, rec.referenced_column; - - sql_statement = 'CREATE OR REPLACE FUNCTION ' || 'StepRun' || rec.referencing_column || '_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + + END; + + ALTER SEQUENCE "step_run_order_seq" OWNED BY "StepRun".order; + + RAISE NOTICE 'Migration successful EXIT'; + EXIT; + + EXCEPTION + WHEN OTHERS THEN + RAISE NOTICE 'Migration failed, retrying...'; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + + retry_count := retry_count + 1; + RAISE NOTICE 'Attempt %', retry_count; + PERFORM pg_sleep(sleep_interval / 1000.0); + IF retry_count = max_retries THEN + RAISE NOTICE 'Migration failed after % attempts', retry_count; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + RAISE EXCEPTION 'Migration failed after % attempts', retry_count; + END IF; + END; + END LOOP; +END $$; + +COMMIT; + +DO $$ +BEGIN + RAISE NOTICE 'Manually creating the FK triggers'; +END $$; + +BEGIN TRANSACTION; + +CREATE OR REPLACE FUNCTION StepRunA_fk_trigger_function() RETURNS TRIGGER AS $function_body$ BEGIN - IF NEW."'|| rec.referencing_column || '" IS NOT NULL THEN + IF NEW."A" IS NOT NULL THEN IF NOT EXISTS ( SELECT 1 FROM "StepRun" - WHERE "' || rec.referenced_column || '" = NEW."' || rec.referencing_column || '" + WHERE "id" = NEW."A" ) THEN - RAISE EXCEPTION ''Foreign key violation: ' || 'StepRun' || ' with ' || rec.referenced_column || ' = % does not exist.'', NEW."' || rec.referencing_column || '"; + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."A"; END IF; END IF; RETURN NEW; END; - $function_body$ LANGUAGE plpgsql;'; + $function_body$ LANGUAGE plpgsql; - RAISE NOTICE 'Executing: %', sql_statement; +CREATE TRIGGER "_StepRunOrder_A_fkey_fk_insert_trigger" BEFORE INSERT ON "_StepRunOrder" FOR EACH ROW +EXECUTE FUNCTION StepRunA_fk_trigger_function(); - EXECUTE sql_statement; +CREATE TRIGGER "_StepRunOrder_A_fkey_fk_update_trigger" BEFORE +UPDATE ON "_StepRunOrder" FOR EACH ROW +EXECUTE FUNCTION StepRunA_fk_trigger_function(); - RAISE NOTICE 'Created trigger function for %', rec.constraint_name; +COMMIT; - sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_insert_trigger" - BEFORE INSERT ON ' || rec.referencing_table || ' - FOR EACH ROW - EXECUTE FUNCTION ' || 'StepRun'||rec.referencing_column|| '_fk_trigger_function();'; - RAISE NOTICE 'Executing: %', sql_statement; - EXECUTE sql_statement; - sql_statement = 'CREATE TRIGGER "' || rec.constraint_name || '_fk_update_trigger" - BEFORE UPDATE ON ' || rec.referencing_table || ' - FOR EACH ROW - EXECUTE FUNCTION ' || 'StepRun' || rec.referencing_column|| '_fk_trigger_function();'; - RAISE NOTICE 'Executing: %', sql_statement; +ALTER TABLE "_StepRunOrder" +DROP CONSTRAINT "_StepRunOrder_A_fkey"; - EXECUTE sql_statement; +DO $$ +BEGIN + RAISE NOTICE 'Dropped _StepRunOrder_A_fkey'; +END $$; - sql_statement = 'ALTER TABLE ' || rec.referencing_table || ' DROP CONSTRAINT "' || rec.constraint_name || '"'; - RAISE NOTICE 'Executing: %', sql_statement; - EXECUTE sql_statement; +BEGIN TRANSACTION; +CREATE OR REPLACE FUNCTION StepRunB_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."B" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."B" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."B"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; - END LOOP; - END; +CREATE TRIGGER "_StepRunOrder_B_fkey_fk_insert_trigger" BEFORE INSERT ON "_StepRunOrder" FOR EACH ROW +EXECUTE FUNCTION StepRunB_fk_trigger_function(); - +CREATE TRIGGER "_StepRunOrder_B_fkey_fk_update_trigger" BEFORE +UPDATE ON "_StepRunOrder" FOR EACH ROW +EXECUTE FUNCTION StepRunB_fk_trigger_function(); + +COMMIT; + +ALTER TABLE "_StepRunOrder" +DROP CONSTRAINT "_StepRunOrder_B_fkey"; +BEGIN TRANSACTION ; +CREATE OR REPLACE FUNCTION StepRunstepRunId_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."stepRunId" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."stepRunId" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."stepRunId"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; + +CREATE TRIGGER "StepRunResultArchive_stepRunId_fkey_fk_insert_trigger" BEFORE INSERT ON "StepRunResultArchive" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +CREATE TRIGGER "StepRunResultArchive_stepRunId_fkey_fk_update_trigger" BEFORE +UPDATE ON "StepRunResultArchive" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +COMMIT; + +DO $$ +BEGIN + RAISE NOTICE 'created StepRunResultArchive triggers'; +END $$; + +ALTER TABLE "StepRunResultArchive" +DROP CONSTRAINT "StepRunResultArchive_stepRunId_fkey"; + +BEGIN TRANSACTION; + +CREATE +OR REPLACE FUNCTION StepRunstepRunId_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."stepRunId" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."stepRunId" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."stepRunId"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; + +CREATE TRIGGER "LogLine_stepRunId_fkey_fk_insert_trigger" BEFORE INSERT ON "LogLine" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +CREATE TRIGGER "LogLine_stepRunId_fkey_fk_update_trigger" BEFORE +UPDATE ON "LogLine" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +COMMIT; + +ALTER TABLE "LogLine" +DROP CONSTRAINT "LogLine_stepRunId_fkey"; + +BEGIN TRANSACTION; + +CREATE +OR REPLACE FUNCTION StepRunparentStepRunId_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."parentStepRunId" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."parentStepRunId" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."parentStepRunId"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; + +CREATE TRIGGER "WorkflowTriggerScheduledRef_parentStepRunId_fkey_fk_insert_trigger" BEFORE INSERT ON "WorkflowTriggerScheduledRef" FOR EACH ROW +EXECUTE FUNCTION StepRunparentStepRunId_fk_trigger_function(); + +CREATE TRIGGER "WorkflowTriggerScheduledRef_parentStepRunId_fkey_fk_update_trigger" BEFORE +UPDATE ON "WorkflowTriggerScheduledRef" FOR EACH ROW +EXECUTE FUNCTION StepRunparentStepRunId_fk_trigger_function(); + +COMMIT; + +ALTER TABLE "WorkflowTriggerScheduledRef" +DROP CONSTRAINT "WorkflowTriggerScheduledRef_parentStepRunId_fkey"; + +BEGIN TRANSACTION; + +CREATE OR REPLACE FUNCTION StepRunparentStepRunId_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."parentStepRunId" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."parentStepRunId" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."parentStepRunId"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; + +CREATE TRIGGER "WorkflowRun_parentStepRunId_fkey_fk_insert_trigger" BEFORE INSERT ON "WorkflowRun" FOR EACH ROW +EXECUTE FUNCTION StepRunparentStepRunId_fk_trigger_function(); + +CREATE TRIGGER "WorkflowRun_parentStepRunId_fkey_fk_update_trigger" BEFORE +UPDATE ON "WorkflowRun" FOR EACH ROW +EXECUTE FUNCTION StepRunparentStepRunId_fk_trigger_function(); + +COMMIT; + +ALTER TABLE "WorkflowRun" +DROP CONSTRAINT "WorkflowRun_parentStepRunId_fkey"; + +DO $$ +BEGIN + RAISE NOTICE 'dropped WorkflowRun_parentStepRunId_fkey'; +END $$; + + +BEGIN TRANSACTION; + +CREATE +OR REPLACE FUNCTION StepRunstepRunId_fk_trigger_function() RETURNS TRIGGER AS $function_body$ + BEGIN + IF NEW."stepRunId" IS NOT NULL THEN + IF NOT EXISTS ( + SELECT 1 + FROM "StepRun" + WHERE "id" = NEW."stepRunId" + ) THEN + RAISE EXCEPTION 'Foreign key violation: StepRun with id = % does not exist.', NEW."stepRunId"; + END IF; + END IF; + RETURN NEW; + END; + $function_body$ LANGUAGE plpgsql; + +CREATE TRIGGER "StreamEvent_stepRunId_fkey_fk_insert_trigger" BEFORE INSERT ON "StreamEvent" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +CREATE TRIGGER "StreamEvent_stepRunId_fkey_fk_update_trigger" BEFORE +UPDATE ON "StreamEvent" FOR EACH ROW +EXECUTE FUNCTION StepRunstepRunId_fk_trigger_function(); + +COMMIT; + +ALTER TABLE "StreamEvent" +DROP CONSTRAINT "StreamEvent_stepRunId_fkey"; + +DO $$ + +BEGIN + + RAISE NOTICE 'Finished manually converting the FK to triggers'; + +END $$; + +-- we are done with the transaction and did not exception out +DO $$ +BEGIN + + RAISE NOTICE 'Let everything else have a chance'; + PERFORM pg_sleep(10); + RAISE NOTICE 'OK done sleeping'; +END $$; + + +DO $$ +DECLARE + attempt INT; +BEGIN + FOR attempt IN 1..20 LOOP + BEGIN + RAISE NOTICE 'Attempting to drop table "StepRun_old" (attempt %)...', attempt; + + + DROP TABLE "StepRun_old" CASCADE; + + - RAISE NOTICE 'Migration successful EXIT'; EXIT; - EXCEPTION + EXCEPTION WHEN OTHERS THEN + RAISE NOTICE 'Attempt % failed, retrying...', attempt; + IF attempt = 20 THEN + RAISE NOTICE 'Error: %', SQLERRM; + RAISE EXCEPTION 'All attempts failed after 20 retries.'; + END IF; + END; + END LOOP; +END; +$$ LANGUAGE plpgsql; + + + + +DO $$ +BEGIN + + RAISE NOTICE 'Let everything else have a chance'; + PERFORM pg_sleep(10); + RAISE NOTICE 'OK done sleeping now Event table'; +END $$; + + + + +CREATE TABLE + "Event_new" ( + LIKE "Event" INCLUDING ALL, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY + ); + +INSERT INTO "Event_new" SELECT * FROM "Event"; + + +BEGIN TRANSACTION; + +DO $$ +BEGIN + RAISE NOTICE 'GRABBING LOCK on Event at time=%', clock_timestamp(); + LOCK TABLE "Event" IN ACCESS EXCLUSIVE MODE; +END $$; + +ALTER TABLE "Event" +RENAME TO "Event_backup"; + +ALTER TABLE "Event_new" +RENAME TO "Event"; + +INSERT INTO + "Event" +SELECT + * +FROM + "Event_backup" +WHERE + "updatedAt" >= ( + SELECT + max("updatedAt") + FROM + "Event" + ) + AND NOT EXISTS ( + SELECT + 1 + FROM + "Event" + WHERE + "Event"."id" = "Event_backup"."id" + ); + +; + +ALTER TABLE "Event" +ADD CONSTRAINT "Event_replayedFromId_fkey" FOREIGN KEY ("replayedFromId") REFERENCES "Event" ("id") ON DELETE SET NULL ON UPDATE CASCADE NOT VALID; + +DO $$ +BEGIN + RAISE NOTICE 'RELEASED LOCK on Event at time=%', clock_timestamp(); +END $$; + +COMMIT; + + + +DO $$ +DECLARE + attempt INT; +BEGIN + FOR attempt IN 1..20 LOOP + BEGIN + RAISE NOTICE 'Attempting to drop table "Event_backup" (attempt %)...', attempt; + + + DROP TABLE "Event_backup" CASCADE; + + + + EXIT; + EXCEPTION WHEN OTHERS THEN + + + RAISE NOTICE 'Attempt % failed, retrying...', attempt; + if attempt = 20 THEN + RAISE EXCEPTION 'All attempts failed after 20 retries.'; + END IF; + END; + END LOOP; + +END; +$$ LANGUAGE plpgsql; + + + +-- Indexes: +-- "Event_pkey" PRIMARY KEY, btree (id) +-- "Event_createdAt_idx" btree ("createdAt") +-- "Event_id_key" UNIQUE, btree (id) +-- "Event_tenantId_createdAt_idx" btree ("tenantId", "createdAt") +-- "Event_tenantId_idx" btree ("tenantId") +-- Foreign-key constraints: +-- "Event_replayedFromId_fkey" FOREIGN KEY ("replayedFromId") REFERENCES "Event"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- Referenced by: +-- TABLE ""Event"" CONSTRAINT "Event_replayedFromId_fkey" FOREIGN KEY ("replayedFromId") REFERENCES "Event"(id) ON UPDATE CASCADE ON DELETE SET NULL + +DO $$ +BEGIN + RAISE NOTICE 'Migrating JobRun time=%', clock_timestamp(); +END $$; + +CREATE TABLE + "JobRun_new" ( + LIKE "JobRun" INCLUDING ALL, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY + ); + +INSERT INTO + "JobRun_new" +SELECT + * +FROM + "JobRun"; + + +DO $$ +BEGIN + RAISE NOTICE 'About to modify Jobrun=%', clock_timestamp(); +END $$; + +DO $$ +DECLARE + retry_count INT := 0; + max_retries INT := 20; +BEGIN + WHILE retry_count < max_retries + LOOP + BEGIN + + RAISE NOTICE 'GRABBING LOCK on JobRun at time=%', clock_timestamp(); + LOCK TABLE "JobRun" IN ACCESS EXCLUSIVE MODE; + +RAISE NOTICE 'Altering JobRun table'; +ALTER TABLE "JobRun" RENAME TO "JobRun_backup"; +ALTER TABLE "JobRun_new" RENAME TO "JobRun"; + +INSERT INTO "JobRun" SELECT * FROM "JobRun_backup" WHERE "updatedAt" >= (SELECT max("updatedAt") FROM "JobRun") AND NOT EXISTS ( + SELECT 1 FROM "JobRun" WHERE "JobRun"."id" = "JobRun_backup"."id" + ); + + + + RAISE NOTICE 'RELEASED LOCK on JobRun at time=%', clock_timestamp(); + EXIT; + EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'Migration failed, retrying...'; RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; - -- ROLLBACK; + retry_count := retry_count + 1; RAISE NOTICE 'Attempt %', retry_count; - PERFORM pg_sleep(sleep_interval / 1000.0); + PERFORM pg_sleep(5); + IF retry_count = max_retries THEN + RAISE NOTICE 'JobRun Migration failed after % attempts', retry_count; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + RAISE EXCEPTION 'Migration failed after % attempts', retry_count; + END IF; END; END LOOP; END $$; -CREATE TABLE "Event_new" ( - LIKE "Event" INCLUDING CONSTRAINTS, - "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY -); -INSERT INTO "Event_new" SELECT * FROM "Event"; -ALTER TABLE "Event" RENAME TO "Event_backup"; -ALTER TABLE "Event_new" RENAME TO "Event"; -DROP TABLE "Event_backup" CASCADE; -CREATE TABLE "JobRun_new" ( - LIKE "JobRun" INCLUDING CONSTRAINTS, - "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY -); -INSERT INTO "JobRun_new" SELECT * FROM "JobRun"; -ALTER TABLE "JobRun" RENAME TO "JobRun_backup"; -ALTER TABLE "JobRun_new" RENAME TO "JobRun"; +DO $$ +BEGIN + RAISE NOTICE 'Finished Jobrun bulk changes'; +END $$; + +DO $$ +DECLARE + attempt INT := 0; + max_retries INT := 20; +BEGIN + FOR attempt IN 1..max_retries LOOP + BEGIN + RAISE NOTICE 'Attempting to add constraint (attempt %)...', attempt; + + ALTER TABLE "JobRun" + ADD CONSTRAINT "JobRun_workflowRunId_fkey" + FOREIGN KEY ("workflowRunId") + REFERENCES "WorkflowRun" ("id") + ON DELETE CASCADE + ON UPDATE CASCADE + NOT VALID; + + + RETURN; + EXCEPTION + WHEN SQLSTATE '40001' THEN + RAISE NOTICE 'Deadlock detected on attempt %; retrying...', attempt; + PERFORM pg_sleep(5); -- Sleep for 5 seconds before retrying + WHEN OTHERS THEN + RAISE NOTICE 'Error on attempt %: %', attempt, SQLERRM; + PERFORM pg_sleep(5); -- Sleep before retrying on other errors + END; + END LOOP; + + RAISE EXCEPTION 'All attempts failed after % retries.', max_retries; +END; + + +$$ LANGUAGE plpgsql; +DO $$ +BEGIN + RAISE NOTICE 'added jobrun constraint'; +END $$; + + + + + + + + + + +DO $$ +DECLARE + attempt INT; +BEGIN + FOR attempt IN 1..20 LOOP + BEGIN + + + + DROP TABLE "JobRun_backup" CASCADE; + + + + RETURN; + EXCEPTION WHEN OTHERS THEN + RAISE NOTICE 'Error is %', SQLERRM; + RAISE NOTICE 'Attempt % failed, retrying...', attempt; + IF attempt = 20 THEN + RAISE EXCEPTION 'All attempts failed after 20 retries.'; + END IF; + END; + END LOOP; + +END; +$$ LANGUAGE plpgsql; + + + +-- can skip this cause we create it in a second +-- ALTER TABLE "JobRunLookupData" +-- ADD CONSTRAINT "JobRunLookupData_jobRunId_fkey" +-- FOREIGN KEY ("jobRunId") +-- REFERENCES "JobRun" ("id") +-- ON DELETE CASCADE +-- ON UPDATE CASCADE +-- NOT VALID; +-- Indexes: +-- "JobRun_pkey" PRIMARY KEY, btree (id) +-- "JobRun_deletedAt_idx" btree ("deletedAt") +-- "JobRun_id_key" UNIQUE, btree (id) +-- "JobRun_workflowRunId_tenantId_idx" btree ("workflowRunId", "tenantId") +-- Foreign-key constraints: +-- "JobRun_workflowRunId_fkey" FOREIGN KEY ("workflowRunId") REFERENCES "WorkflowRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +-- Referenced by: +-- TABLE ""JobRunLookupData"" CONSTRAINT "JobRunLookupData_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +-- TABLE ""StepRun"" CONSTRAINT "StepRun_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +CREATE TABLE + "JobRunLookupData_new" ( + LIKE "JobRunLookupData" INCLUDING ALL, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY + ); + +INSERT INTO + "JobRunLookupData_new" +SELECT + * +FROM + "JobRunLookupData"; + +BEGIN TRANSACTION; + +SET + LOCAL lock_timeout = '25s'; + +SET + LOCAL statement_timeout = '0'; + +DO $$ +DECLARE + retry_count INT := 0; + max_retries INT := 20; +BEGIN + WHILE retry_count < max_retries + +LOOP + +BEGIN + + + RAISE NOTICE 'GRABBING LOCK on JobRunLookupData at time=%', clock_timestamp(); + LOCK TABLE "JobRunLookupData" IN ACCESS EXCLUSIVE MODE; + + ALTER TABLE "JobRunLookupData" RENAME TO "JobRunLookupData_backup"; + ALTER TABLE "JobRunLookupData_new" RENAME TO "JobRunLookupData"; + + INSERT INTO "JobRunLookupData" + SELECT * FROM "JobRunLookupData_backup" + WHERE "updatedAt" = (SELECT max("updatedAt") FROM "JobRunLookupData") AND NOT EXISTS ( + SELECT 1 FROM "JobRunLookupData" WHERE "JobRunLookupData"."id" = "JobRunLookupData_backup"."id" + ); + + INSERT INTO "JobRunLookupData" + SELECT * FROM "JobRunLookupData_backup" + WHERE "updatedAt" > (SELECT max("updatedAt") FROM "JobRunLookupData") AND NOT EXISTS ( + SELECT 1 FROM "JobRunLookupData" WHERE "JobRunLookupData"."id" = "JobRunLookupData_backup"."id" + ); + + + + RAISE NOTICE 'RELEASED LOCK on JobRunLookupData at time=%', clock_timestamp(); + EXIT; + EXCEPTION + WHEN OTHERS THEN + RAISE NOTICE 'Migration failed, retrying...'; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + + retry_count := retry_count + 1; + RAISE NOTICE 'Attempt %', retry_count; + PERFORM pg_sleep(5); + IF retry_count = max_retries THEN + + RAISE NOTICE 'JobRun Migration failed after % attempts', retry_count; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + RAISE EXCEPTION 'Migration on JobRunLookupData failed after % attempts', retry_count; + END IF; + END; + END LOOP; +END $$; + +COMMIT; + +DO $$ +BEGIN + RAISE NOTICE 'modified JobRunLookupData'; +END $$; + +ALTER TABLE "JobRunLookupData" +ADD CONSTRAINT "JobRunLookupData_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun" ("id") ON DELETE CASCADE ON UPDATE CASCADE NOT VALID; + +DO $$ +BEGIN + RAISE NOTICE 'added JobRunLookupData constraint'; +END $$; + +BEGIN TRANSACTION; + +DO $$ +DECLARE + attempt INT; +BEGIN + FOR attempt IN 1..20 LOOP + BEGIN + RAISE NOTICE 'Attempting to drop table "JobRunLookupData_backup" (attempt %)...', attempt; + + + DROP TABLE "JobRunLookupData_backup" CASCADE; + + + + EXIT; + EXCEPTION WHEN OTHERS THEN + -- Rollback if there's an error + RAISE NOTICE 'Attempt % failed, retrying...', attempt; + if attempt = 20 THEN + RAISE EXCEPTION 'All attempts failed after 20 retries.'; + END IF; + END; + END LOOP; + + +END; +$$ LANGUAGE plpgsql; + +COMMIT; + +BEGIN TRANSACTION; + +-- Indexes: +-- "JobRunLookupData_pkey" PRIMARY KEY, btree (id) +-- "JobRunLookupData_id_key" UNIQUE, btree (id) +-- "JobRunLookupData_jobRunId_key" UNIQUE, btree ("jobRunId") +-- "JobRunLookupData_jobRunId_tenantId_key" UNIQUE, btree ("jobRunId", "tenantId") +-- Foreign-key constraints: +-- "JobRunLookupData_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +DO $$ +DECLARE + retry_count INT := 0; + max_retries INT := 20; + + +BEGIN + RAISE NOTICE 'Starting with WorkflowRunTriggeredBy at time=%', clock_timestamp(); + CREATE TABLE "WorkflowRunTriggeredBy_new" ( + LIKE "WorkflowRunTriggeredBy" INCLUDING ALL, + "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY + ); + + INSERT INTO "WorkflowRunTriggeredBy_new" SELECT * FROM "WorkflowRunTriggeredBy"; + while retry_count < max_retries + LOOP + BEGIN + RAISE NOTICE 'GRABBING LOCK on WorkflowRunTriggeredBy at time=%', clock_timestamp(); + LOCK TABLE "WorkflowRunTriggeredBy" IN ACCESS EXCLUSIVE MODE; + + ALTER TABLE "WorkflowRunTriggeredBy" RENAME TO "WorkflowRunTriggeredBy_backup"; + ALTER TABLE "WorkflowRunTriggeredBy_new" RENAME TO "WorkflowRunTriggeredBy"; + + INSERT INTO "WorkflowRunTriggeredBy" + SELECT * FROM "WorkflowRunTriggeredBy_backup" + WHERE "updatedAt" = (SELECT max("updatedAt") FROM "WorkflowRunTriggeredBy") AND NOT EXISTS ( + SELECT 1 FROM "WorkflowRunTriggeredBy" WHERE "WorkflowRunTriggeredBy"."id" = "WorkflowRunTriggeredBy_backup"."id" + ); + + + INSERT INTO "WorkflowRunTriggeredBy" + SELECT * FROM "WorkflowRunTriggeredBy_backup" + WHERE "updatedAt" > (SELECT max("updatedAt") FROM "WorkflowRunTriggeredBy") ; + + + RAISE NOTICE 'RELEASED LOCK on WorkflowRunTriggeredBy at time=%', clock_timestamp(); + EXIT; + EXCEPTION + WHEN OTHERS THEN + RAISE NOTICE 'Migration failed, retrying...'; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + + retry_count := retry_count + 1; + RAISE NOTICE 'Attempt %', retry_count; + PERFORM pg_sleep(5); + IF retry_count = max_retries THEN + RAISE NOTICE 'JobRun Migration failed after % attempts', retry_count; + RAISE NOTICE 'SQLSTATE: %, Message: %', SQLSTATE, SQLERRM; + RAISE EXCEPTION 'Migration on WorkflowRunTriggeredBy failed after % attempts', retry_count; + END IF; + END; + END LOOP; +END $$; + +COMMIT; + + + +DO $$ +DECLARE + attempt INT := 0; + max_retries INT := 20; +BEGIN + FOR attempt IN 1..max_retries LOOP + BEGIN + RAISE NOTICE 'Attempting to add constraint (attempt %)...', attempt; + + -- Attempt to add the constraint + ALTER TABLE "WorkflowRunTriggeredBy" + ADD CONSTRAINT "WorkflowRunTriggeredBy_cronParentId_cronSchedule_fkey" + FOREIGN KEY ("cronParentId", "cronSchedule") + REFERENCES "WorkflowTriggerCronRef" ("parentId", "cron") + ON DELETE SET NULL + ON UPDATE CASCADE + NOT VALID; + + -- If successful, exit the loop and end the DO block + RAISE NOTICE 'Constraint added successfully on attempt %', attempt; + RETURN; + EXCEPTION + WHEN SQLSTATE '40001' THEN -- Deadlock error code + RAISE NOTICE 'Deadlock detected on attempt %; retrying...', attempt; + PERFORM pg_sleep(5); -- Sleep for 5 seconds before retrying + WHEN OTHERS THEN + RAISE NOTICE 'Error on attempt %: %', attempt, SQLERRM; + PERFORM pg_sleep(5); -- Sleep before retrying on other errors + END; + END LOOP; + + -- If we exhaust all attempts, raise an exception + RAISE EXCEPTION 'All attempts failed after % retries.', max_retries; +END; +$$ LANGUAGE plpgsql; + -DROP TABLE "JobRun_backup" CASCADE; -CREATE TABLE "JobRunLookupData_new" ( - LIKE "JobRunLookupData" INCLUDING CONSTRAINTS, - "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY -); -INSERT INTO "JobRunLookupData_new" SELECT * FROM "JobRunLookupData"; -ALTER TABLE "JobRunLookupData" RENAME TO "JobRunLookupData_backup"; -ALTER TABLE "JobRunLookupData_new" RENAME TO "JobRunLookupData"; +DO $$ +DECLARE + attempt INT := 0; + max_retries INT := 20; +BEGIN + FOR attempt IN 1..max_retries LOOP + BEGIN + RAISE NOTICE 'Attempting to add constraint (attempt %)...', attempt; + + -- Attempt to add the constraint + ALTER TABLE "WorkflowRunTriggeredBy" + ADD CONSTRAINT "WorkflowRunTriggeredBy_scheduledId_fkey" + FOREIGN KEY ("scheduledId") + REFERENCES "WorkflowTriggerScheduledRef" ("id") + ON DELETE SET NULL + ON UPDATE CASCADE + NOT VALID; + + -- If successful, exit the loop and end the DO block + RAISE NOTICE 'Constraint added successfully on attempt %', attempt; + RETURN; + EXCEPTION + WHEN SQLSTATE '40001' THEN -- Deadlock error code + RAISE NOTICE 'Deadlock detected on attempt %; retrying...', attempt; + PERFORM pg_sleep(5); -- Sleep for 5 seconds before retrying + WHEN OTHERS THEN + RAISE NOTICE 'Error on attempt %: %', attempt, SQLERRM; + PERFORM pg_sleep(5); -- Sleep before retrying on other errors + END; + END LOOP; + + -- If we exhaust all attempts, raise an exception + RAISE EXCEPTION 'All attempts failed after % retries.', max_retries; +END; +$$ LANGUAGE plpgsql; + + + + +DO $$ +DECLARE + attempt INT; +BEGIN + FOR attempt IN 1..20 LOOP + BEGIN + RAISE NOTICE 'Attempting to drop table "WorkflowRunTriggeredBy_backup" (attempt %)...', attempt; + + + DROP TABLE "WorkflowRunTriggeredBy_backup" CASCADE; + + + + RETURN; + EXCEPTION WHEN OTHERS THEN + + RAISE NOTICE 'Attempt % failed, retrying...', attempt; + if attempt = 20 THEN + RAISE EXCEPTION 'All attempts failed after 20 retries.'; + END IF; + END; + END LOOP; + +END; +$$ LANGUAGE plpgsql; + + -DROP TABLE "JobRunLookupData_backup" CASCADE; -CREATE TABLE "WorkflowRunTriggeredBy_new" ( - LIKE "WorkflowRunTriggeredBy" INCLUDING CONSTRAINTS, - "identityId" bigint NOT NULL GENERATED ALWAYS AS IDENTITY -); +-- Indexes: +-- "WorkflowRunTriggeredBy_pkey" PRIMARY KEY, btree (id) +-- "WorkflowRunTriggeredBy_eventId_idx" btree ("eventId") +-- "WorkflowRunTriggeredBy_id_key" UNIQUE, btree (id) +-- "WorkflowRunTriggeredBy_parentId_idx" btree ("parentId") +-- "WorkflowRunTriggeredBy_parentId_key" UNIQUE, btree ("parentId") +-- "WorkflowRunTriggeredBy_scheduledId_key" UNIQUE, btree ("scheduledId") +-- "WorkflowRunTriggeredBy_tenantId_idx" btree ("tenantId") +-- Foreign-key constraints: +-- "WorkflowRunTriggeredBy_cronParentId_cronSchedule_fkey" FOREIGN KEY ("cronParentId", "cronSchedule") REFERENCES "WorkflowTriggerCronRef"("parentId", cron) ON UPDATE CASCADE ON DELETE SET NULL +-- "WorkflowRunTriggeredBy_scheduledId_fkey" FOREIGN KEY ("scheduledId") REFERENCES "WorkflowTriggerScheduledRef"(id) ON UPDATE CASCADE ON DELETE SET NULL +DO $$ +BEGIN + RAISE NOTICE 'Ending at time=%', clock_timestamp(); +END $$; + +-- Step run should have +-- Indexes: +-- "StepRun_pkey" PRIMARY KEY, btree (id) +-- "StepRun_createdAt_idx" btree ("createdAt") +-- "StepRun_deletedAt_idx" btree ("deletedAt") +-- "StepRun_id_key" UNIQUE, btree (id) +-- "StepRun_id_tenantId_idx" btree (id, "tenantId") +-- "StepRun_jobRunId_status_idx" btree ("jobRunId", status) +-- "StepRun_jobRunId_status_tenantId_idx" btree ("jobRunId", status, "tenantId") WHERE status = 'PENDING'::"StepRunStatus" +-- "StepRun_jobRunId_status_tenantId_requeueAfter_idx" btree ("jobRunId", status, "tenantId", "requeueAfter") +-- "StepRun_jobRunId_tenantId_order_idx" btree ("jobRunId", "tenantId", "order") +-- "StepRun_queue_createdAt_idx" btree (queue, "createdAt") +-- "StepRun_requeueAfter_idx" btree ("requeueAfter") +-- "StepRun_status_idx" btree (status) +-- "StepRun_status_timeoutAt_tickerId_idx" btree (status, "timeoutAt", "tickerId") +-- "StepRun_stepId_idx" btree ("stepId") +-- "StepRun_tenantId_idx" btree ("tenantId") +-- "StepRun_timeoutAt_idx" btree ("timeoutAt") +-- "StepRun_workerId_idx" btree ("workerId") +-- Foreign-key constraints: +-- "StepRun_jobRunId_fkey" FOREIGN KEY ("jobRunId") REFERENCES "JobRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +-- "StepRun_workerId_fkey" FOREIGN KEY ("workerId") REFERENCES "Worker"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- Referenced by: +-- TABLE ""LogLine"" CONSTRAINT "LogLine_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- TABLE ""StepRunResultArchive"" CONSTRAINT "StepRunResultArchive_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +-- TABLE ""StreamEvent"" CONSTRAINT "StreamEvent_stepRunId_fkey" FOREIGN KEY ("stepRunId") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- TABLE ""WorkflowRun"" CONSTRAINT "WorkflowRun_parentStepRunId_fkey" FOREIGN KEY ("parentStepRunId") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- TABLE ""WorkflowTriggerScheduledRef"" CONSTRAINT "WorkflowTriggerScheduledRef_parentStepRunId_fkey" FOREIGN KEY ("parentStepRunId") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE SET NULL +-- TABLE ""_StepRunOrder"" CONSTRAINT "_StepRunOrder_A_fkey" FOREIGN KEY ("A") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +-- TABLE ""_StepRunOrder"" CONSTRAINT "_StepRunOrder_B_fkey" FOREIGN KEY ("B") REFERENCES "StepRun"(id) ON UPDATE CASCADE ON DELETE CASCADE +DO $$ +BEGIN + RAISE NOTICE 'Renaming indexes starting at time=%', clock_timestamp(); +END $$; + +-- Rename an index from "Event_new_createdAt_idx" to "Event_createdAt_idx" +ALTER INDEX "Event_new_createdAt_idx" +RENAME TO "Event_createdAt_idx"; + +-- Rename an index from "Event_new_id_idx" to "Event_id_key" +ALTER INDEX "Event_new_id_idx" +RENAME TO "Event_id_key"; + +-- Rename an index from "Event_new_tenantId_createdAt_idx" to "Event_tenantId_createdAt_idx" +ALTER INDEX "Event_new_tenantId_createdAt_idx" +RENAME TO "Event_tenantId_createdAt_idx"; + +-- Rename an index from "Event_new_tenantId_idx" to "Event_tenantId_idx" +ALTER INDEX "Event_new_tenantId_idx" +RENAME TO "Event_tenantId_idx"; + +-- Rename an index from "JobRun_new_deletedAt_idx" to "JobRun_deletedAt_idx" +ALTER INDEX "JobRun_new_deletedAt_idx" +RENAME TO "JobRun_deletedAt_idx"; + +-- Rename an index from "JobRun_new_id_idx" to "JobRun_id_key" +ALTER INDEX "JobRun_new_id_idx" +RENAME TO "JobRun_id_key"; -INSERT INTO "WorkflowRunTriggeredBy_new" SELECT * FROM "WorkflowRunTriggeredBy"; +-- Rename an index from "JobRun_new_workflowRunId_tenantId_idx" to "JobRun_workflowRunId_tenantId_idx" +ALTER INDEX "JobRun_new_workflowRunId_tenantId_idx" +RENAME TO "JobRun_workflowRunId_tenantId_idx"; -ALTER TABLE "WorkflowRunTriggeredBy" RENAME TO "WorkflowRunTriggeredBy_backup"; -ALTER TABLE "WorkflowRunTriggeredBy_new" RENAME TO "WorkflowRunTriggeredBy"; +-- Rename an index from "JobRunLookupData_new_id_idx" to "JobRunLookupData_id_key" +ALTER INDEX "JobRunLookupData_new_id_idx" +RENAME TO "JobRunLookupData_id_key"; -DROP TABLE "WorkflowRunTriggeredBy_backup" CASCADE; +-- Rename an index from "JobRunLookupData_new_jobRunId_idx" to "JobRunLookupData_jobRunId_key" +ALTER INDEX "JobRunLookupData_new_jobRunId_idx" +RENAME TO "JobRunLookupData_jobRunId_key"; -DROP TABLE "StepRun_old" CASCADE; \ No newline at end of file +-- Rename an index from "JobRunLookupData_new_jobRunId_tenantId_idx" to "JobRunLookupData_jobRunId_tenantId_key" +ALTER INDEX "JobRunLookupData_new_jobRunId_tenantId_idx" +RENAME TO "JobRunLookupData_jobRunId_tenantId_key"; + +-- Drop index "StepRun_updatedAt_idx" from table: "StepRun" +DROP INDEX "StepRun_updatedAt_idx"; + +-- Rename an index from "StepRun_new_id_key" to "StepRun_id_key" +ALTER INDEX "StepRun_new_id_key" +RENAME TO "StepRun_id_key"; + +-- Rename an index from "StepRun_new_jobRunId_status_tenantId_idx" to "StepRun_jobRunId_status_tenantId_idx" +ALTER INDEX "StepRun_new_jobRunId_status_tenantId_idx" +RENAME TO "StepRun_jobRunId_status_tenantId_idx"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_eventId_idx" to "WorkflowRunTriggeredBy_eventId_idx" +ALTER INDEX "WorkflowRunTriggeredBy_new_eventId_idx" +RENAME TO "WorkflowRunTriggeredBy_eventId_idx"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_id_idx" to "WorkflowRunTriggeredBy_id_key" +ALTER INDEX "WorkflowRunTriggeredBy_new_id_idx" +RENAME TO "WorkflowRunTriggeredBy_id_key"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_parentId_idx" to "WorkflowRunTriggeredBy_parentId_key" +ALTER INDEX "WorkflowRunTriggeredBy_new_parentId_idx" +RENAME TO "WorkflowRunTriggeredBy_parentId_key"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_parentId_idx1" to "WorkflowRunTriggeredBy_parentId_idx" +ALTER INDEX "WorkflowRunTriggeredBy_new_parentId_idx1" +RENAME TO "WorkflowRunTriggeredBy_parentId_idx"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_scheduledId_idx" to "WorkflowRunTriggeredBy_scheduledId_key" +ALTER INDEX "WorkflowRunTriggeredBy_new_scheduledId_idx" +RENAME TO "WorkflowRunTriggeredBy_scheduledId_key"; + +-- Rename an index from "WorkflowRunTriggeredBy_new_tenantId_idx" to "WorkflowRunTriggeredBy_tenantId_idx" +ALTER INDEX "WorkflowRunTriggeredBy_new_tenantId_idx" +RENAME TO "WorkflowRunTriggeredBy_tenantId_idx"; + +-- Modify "StepRun" table +-- this constraint does not exist bu atlas things it does so we need to drop it +ALTER TABLE "StepRun" +DROP CONSTRAINT IF EXISTS "StepRun_new_status_identityId_key"; + +DO $$ +BEGIN + RAISE NOTICE 'Renamed indexes ending at time=%', clock_timestamp(); +END $$; \ No newline at end of file diff --git a/sql/migrations/atlas.sum b/sql/migrations/atlas.sum index 22c25aa49..29beb17d8 100644 --- a/sql/migrations/atlas.sum +++ b/sql/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Uxo91RtnOjhpWS25Nz39EVfrzK0pwzs1DAGBaylqJSI= +h1:uaeLP9is4hFO6F3JMsf3teAo1HRxnb9NkScqJbKD0Jo= 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= @@ -75,6 +75,6 @@ h1:Uxo91RtnOjhpWS25Nz39EVfrzK0pwzs1DAGBaylqJSI= 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:LnfNg2RE/mp8heRU/eM043kBlDnnrquRnIogiUomSYk= -20241121153627_v0.52.1.sql h1:sHprtqRs1yfoB0ZxtMpiI3lsjpm4vnibf5fJqHR9jtE= -20241121195232_v0.52.2.sql h1:XdhEqVm+tws9KLnkyiKB8xRW8xJQ+ynN6r3vmRhx9Ww= +20241121142159_v0.52.0.sql h1:Rvh3mFJtonDIfBbuag9Vdf+971cFLdtlk658qJkE93A= +20241121153627_v0.52.1.sql h1:niuN4pTye/G3uPYuORvj3deY4kQdKSLqFyaxYsTj0Dw= +20241121195232_v0.52.2.sql h1:iMeeV500krRGOlMWnJzq0jt++T6fkzj0PuH7sKNbgZE= diff --git a/sql/schema/schema.sql b/sql/schema/schema.sql index 531fb8a39..636b1c17a 100644 --- a/sql/schema/schema.sql +++ b/sql/schema/schema.sql @@ -520,14 +520,13 @@ CREATE TABLE "queue" TEXT NOT NULL DEFAULT 'default', "priority" INTEGER, "internalRetryCount" INTEGER NOT NULL DEFAULT 0, - "identityId" BIGINT NOT NULL DEFAULT nextval('steprun_identity_id_seq'::regclass), - CONSTRAINT "StepRun_pkey" PRIMARY KEY ("status", "id") + "identityId" BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY, + CONSTRAINT "StepRun_pkey" PRIMARY KEY ("status", "id"), + CONSTRAINT "StepRun_new_identityId_status_unique" UNIQUE ("identityId","status") ) PARTITION BY LIST ("status"); -ALTER TABLE "StepRun" -ADD CONSTRAINT step_run_identity_id_unique UNIQUE ("identityId","status"); CREATE TABLE "StepRun_volatile" PARTITION OF "StepRun" FOR @@ -951,8 +950,6 @@ CREATE TABLE "WorkflowRun" ( "duration" BIGINT, "priority" INTEGER, "insertOrder" INTEGER, - "identityId" BIGINT GENERATED ALWAYS AS IDENTITY, - CONSTRAINT "WorkflowRun_pkey" PRIMARY KEY ("id") );