Skip to content

Commit f411f84

Browse files
committed
chore(db): rebase onto staging, collapse the two migrations into one
- Rebased generic-folders-pinned onto latest origin/staging (6 commits replayed cleanly; one real conflict, a scaffold page deleted upstream in the same window this branch touched it -- took the upstream deletion) - Collapsed 0258 (generic folders/pinned-items) and 0259 (resource-level locking) into a single migration, since both ship in this same PR and neither has been applied anywhere yet -- regenerated via `drizzle-kit generate` for the default auto-name (matching every other migration in this repo) rather than a hand-picked descriptive name, then re-applied the hand-authored trigger + backfill INSERTs drizzle-kit doesn't generate on its own Verified end-to-end against disposable Postgres containers: full 0000-0258 apply from scratch, a from-0257 apply with seeded legacy workflow_folder/workspace_file_folders rows to confirm the backfill (including the locked column) and FK repoint both work correctly, and live tests of the folder_parent_resource_type_match trigger's cross-resourceType/cross-workspace rejection and the unique constraints.
1 parent bd3e047 commit f411f84

5 files changed

Lines changed: 36 additions & 17227 deletions

File tree

packages/db/migrations/0258_generic_folders_and_pinned_items.sql renamed to packages/db/migrations/0258_lyrical_flatman.sql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ CREATE TABLE "pinned_item" (
2222
"pinned_at" timestamp DEFAULT now() NOT NULL
2323
);
2424
--> statement-breakpoint
25+
ALTER TABLE "workflow" DROP CONSTRAINT "workflow_folder_id_workflow_folder_id_fk";
26+
--> statement-breakpoint
27+
ALTER TABLE "workspace_files" DROP CONSTRAINT "workspace_files_folder_id_workspace_file_folders_id_fk";
28+
--> statement-breakpoint
29+
ALTER TABLE "knowledge_base" ADD COLUMN "folder_id" text;--> statement-breakpoint
30+
ALTER TABLE "knowledge_base" ADD COLUMN "locked" boolean DEFAULT false NOT NULL;--> statement-breakpoint
31+
ALTER TABLE "user_table_definitions" ADD COLUMN "folder_id" text;--> statement-breakpoint
32+
ALTER TABLE "user_table_definitions" ADD COLUMN "locked" boolean DEFAULT false NOT NULL;--> statement-breakpoint
33+
ALTER TABLE "workspace_files" ADD COLUMN "locked" boolean DEFAULT false NOT NULL;--> statement-breakpoint
2534
ALTER TABLE "folder" ADD CONSTRAINT "folder_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
2635
ALTER TABLE "folder" ADD CONSTRAINT "folder_workspace_id_workspace_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspace"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
2736
ALTER TABLE "folder" ADD CONSTRAINT "folder_parent_id_folder_id_fk" FOREIGN KEY ("parent_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
@@ -77,15 +86,9 @@ INSERT INTO "folder" (id, resource_type, name, user_id, workspace_id, parent_id,
7786
SELECT id, 'file', name, user_id, workspace_id, parent_id, false, sort_order, created_at, updated_at, deleted_at
7887
FROM "workspace_file_folders";
7988
--> statement-breakpoint
80-
ALTER TABLE "workflow" DROP CONSTRAINT "workflow_folder_id_workflow_folder_id_fk";
81-
--> statement-breakpoint
82-
ALTER TABLE "workspace_files" DROP CONSTRAINT "workspace_files_folder_id_workspace_file_folders_id_fk";
83-
--> statement-breakpoint
84-
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
85-
ALTER TABLE "workspace_files" ADD CONSTRAINT "workspace_files_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
86-
ALTER TABLE "knowledge_base" ADD COLUMN "folder_id" text;--> statement-breakpoint
87-
ALTER TABLE "user_table_definitions" ADD COLUMN "folder_id" text;--> statement-breakpoint
8889
ALTER TABLE "knowledge_base" ADD CONSTRAINT "knowledge_base_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
8990
ALTER TABLE "user_table_definitions" ADD CONSTRAINT "user_table_definitions_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
91+
ALTER TABLE "workflow" ADD CONSTRAINT "workflow_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
92+
ALTER TABLE "workspace_files" ADD CONSTRAINT "workspace_files_folder_id_folder_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folder"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
9093
CREATE INDEX "kb_folder_id_idx" ON "knowledge_base" USING btree ("folder_id");--> statement-breakpoint
91-
CREATE INDEX "user_table_def_folder_id_idx" ON "user_table_definitions" USING btree ("folder_id");
94+
CREATE INDEX "user_table_def_folder_id_idx" ON "user_table_definitions" USING btree ("folder_id");

packages/db/migrations/0259_resource_level_locking.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/db/migrations/meta/0258_snapshot.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"id": "13937a90-1955-46dd-9c43-6d34e74dbe50",
2+
"id": "386d00ba-2b12-4c43-ba92-322dce8130a6",
33
"prevId": "c405fc48-c6bb-4786-863f-3d3e686095b5",
44
"version": "7",
55
"dialect": "postgresql",
@@ -6683,6 +6683,13 @@
66836683
"notNull": true,
66846684
"default": "'{\"maxSize\": 1024, \"minSize\": 1, \"overlap\": 200}'"
66856685
},
6686+
"locked": {
6687+
"name": "locked",
6688+
"type": "boolean",
6689+
"primaryKey": false,
6690+
"notNull": true,
6691+
"default": false
6692+
},
66866693
"deleted_at": {
66876694
"name": "deleted_at",
66886695
"type": "timestamp",
@@ -12097,6 +12104,13 @@
1209712104
"notNull": true,
1209812105
"default": 0
1209912106
},
12107+
"locked": {
12108+
"name": "locked",
12109+
"type": "boolean",
12110+
"primaryKey": false,
12111+
"notNull": true,
12112+
"default": false
12113+
},
1210012114
"archived_at": {
1210112115
"name": "archived_at",
1210212116
"type": "timestamp",
@@ -16198,6 +16212,13 @@
1619816212
"primaryKey": false,
1619916213
"notNull": true
1620016214
},
16215+
"locked": {
16216+
"name": "locked",
16217+
"type": "boolean",
16218+
"primaryKey": false,
16219+
"notNull": true,
16220+
"default": false
16221+
},
1620116222
"deleted_at": {
1620216223
"name": "deleted_at",
1620316224
"type": "timestamp",

0 commit comments

Comments
 (0)