You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(db): make expand-only migration deferral honest in schema.ts
schema.ts still declared .references(() => folder.id) on
workflow.folderId/workspaceFiles.folderId even though the migration
defers adding that FK to a future contract migration (blue/green
safety). That left the drizzle snapshot recording the FK as already
present, so a future `drizzle-kit generate` would never emit the
contract migration to actually add it back.
Drop the .references() from both columns (plain text columns until
the contract phase re-adds them) and regenerate 0258 from scratch so
the snapshot matches the real post-migration schema.
Copy file name to clipboardExpand all lines: packages/db/migrations/0258_lumpy_terrax.sql
+31-6Lines changed: 31 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -22,8 +22,18 @@ CREATE TABLE "pinned_item" (
22
22
"pinned_at"timestamp DEFAULT now() NOT NULL
23
23
);
24
24
--> statement-breakpoint
25
+
-- Drops the FK's old target only, no replacement added here — this strictly loosens
26
+
-- the column (removes a check, adds none), so it cannot reject any write that used to
27
+
-- succeed. Adding a `folder`-targeted FK in this same migration would reject a
28
+
-- still-running old-code pod (blue/green cutover) writing a workflow_folder-only id;
29
+
-- that FK is deferred to a follow-up migration once old code is fully drained
30
+
-- (contract-pending marker on workflow.folderId in schema.ts). App-layer validation
31
+
-- already independently enforces the invariant on both old and new code paths.
32
+
-- migration-safe: strictly loosens the column, no cross-deploy write can be rejected by removing this constraint; see contract-pending marker on workflow.folderId in schema.ts
25
33
ALTERTABLE"workflow" DROP CONSTRAINT"workflow_folder_id_workflow_folder_id_fk";
26
34
--> statement-breakpoint
35
+
-- Same reasoning as the workflow.folder_id drop above.
36
+
-- migration-safe: strictly loosens the column, no cross-deploy write can be rejected by removing this constraint; see contract-pending marker on workspaceFiles.folderId in schema.ts
27
37
ALTERTABLE"workspace_files" DROP CONSTRAINT"workspace_files_folder_id_workspace_file_folders_id_fk";
ALTERTABLE"knowledge_base" ADD CONSTRAINT"knowledge_base_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action;--> statement-breakpoint
121
-
ALTERTABLE"user_table_definitions" ADD CONSTRAINT"user_table_definitions_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action;--> statement-breakpoint
122
-
ALTERTABLE"workflow" ADD CONSTRAINT"workflow_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action;--> statement-breakpoint
123
-
ALTERTABLE"workspace_files" ADD CONSTRAINT"workspace_files_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action;--> statement-breakpoint
124
-
CREATEINDEX "kb_folder_id_idx" ON"knowledge_base" USING btree ("folder_id");--> statement-breakpoint
125
-
CREATEINDEX "user_table_def_folder_id_idx" ON"user_table_definitions" USING btree ("folder_id");
130
+
-- knowledge_base.folder_id / user_table_definitions.folder_id are brand-new columns added
131
+
-- earlier in this same migration (all rows NULL) -- no old or new code reads/writes them
132
+
-- yet, so adding their FK here (unlike workflow/workspace_files above) has zero cross-deploy
133
+
-- write-compatibility risk. NOT VALID + an immediate VALIDATE still avoids the full-table
134
+
-- lock a plain ADD CONSTRAINT would take (validating an all-NULL column is instant either
135
+
-- way, but this keeps the pattern uniform and matches this repo's established precedent,
136
+
-- e.g. migrations/0243_kb_workspace_cascade.sql).
137
+
ALTERTABLE"knowledge_base" ADD CONSTRAINT"knowledge_base_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action NOT VALID;--> statement-breakpoint
ALTERTABLE"user_table_definitions" ADD CONSTRAINT"user_table_definitions_folder_id_folder_id_fk"FOREIGN KEY ("folder_id") REFERENCES"public"."folder"("id") ON DELETEsetnullONUPDATE no action NOT VALID;--> statement-breakpoint
0 commit comments