Skip to content

Commit bd5bd8a

Browse files
committed
regen migration
1 parent 14b7622 commit bd5bd8a

File tree

3 files changed

+8290
-0
lines changed

3 files changed

+8290
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Step 1: Add column as NULLABLE first (instant, no lock)
2+
ALTER TABLE "workflow_execution_logs" ADD COLUMN "workspace_id" text;--> statement-breakpoint
3+
4+
-- Step 2: Backfill workspace_id from workflow table
5+
UPDATE "workflow_execution_logs" wel
6+
SET "workspace_id" = w."workspace_id"
7+
FROM "workflow" w
8+
WHERE wel."workflow_id" = w."id"
9+
AND w."workspace_id" IS NOT NULL;--> statement-breakpoint
10+
11+
-- Step 3: Delete orphaned execution logs (from workflows without workspaces)
12+
DELETE FROM "workflow_execution_logs"
13+
WHERE "workspace_id" IS NULL;--> statement-breakpoint
14+
15+
-- Step 4: Add NOT NULL constraint (safe now - all remaining rows have values)
16+
ALTER TABLE "workflow_execution_logs" ALTER COLUMN "workspace_id" SET NOT NULL;--> statement-breakpoint
17+
18+
-- Step 5: Add foreign key constraint
19+
ALTER TABLE "workflow_execution_logs" ADD CONSTRAINT "workflow_execution_logs_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
20+
21+
-- Step 6: Create indexes
22+
CREATE INDEX "workflow_execution_logs_workspace_started_at_idx" ON "workflow_execution_logs" USING btree ("workspace_id","started_at");--> statement-breakpoint
23+
CREATE INDEX "api_key_workspace_type_idx" ON "api_key" USING btree ("workspace_id","type");--> statement-breakpoint
24+
CREATE INDEX "api_key_user_type_idx" ON "api_key" USING btree ("user_id","type");--> statement-breakpoint
25+
CREATE INDEX "verification_expires_at_idx" ON "verification" USING btree ("expires_at");--> statement-breakpoint
26+
CREATE INDEX "workflow_blocks_type_idx" ON "workflow_blocks" USING btree ("type");

0 commit comments

Comments
 (0)