Skip to content

Commit 760105a

Browse files
authored
🐛 fix: fix db migration snapshot not align with db schema (#10399)
* fix db sql * clean
1 parent e1c813a commit 760105a

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

docs/development/database-schema.dbml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ table documents {
187187
user_id text [not null]
188188
client_id text
189189
editor_data jsonb
190+
slug varchar(255)
190191
accessed_at "timestamp with time zone" [not null, default: `now()`]
191192
created_at "timestamp with time zone" [not null, default: `now()`]
192193
updated_at "timestamp with time zone" [not null, default: `now()`]
@@ -197,6 +198,7 @@ table documents {
197198
file_id [name: 'documents_file_id_idx']
198199
parent_id [name: 'documents_parent_id_idx']
199200
(client_id, user_id) [name: 'documents_client_id_user_id_unique', unique]
201+
(slug, user_id) [name: 'documents_slug_user_id_unique', unique]
200202
}
201203
}
202204

@@ -214,7 +216,6 @@ table files {
214216
metadata jsonb
215217
chunk_task_id uuid
216218
embedding_task_id uuid
217-
slug text [unique]
218219
accessed_at "timestamp with time zone" [not null, default: `now()`]
219220
created_at "timestamp with time zone" [not null, default: `now()`]
220221
updated_at "timestamp with time zone" [not null, default: `now()`]
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
ALTER TABLE "documents" ADD COLUMN IF NOT EXISTS "slug" varchar(255);--> statement-breakpoint
2-
DO $$ BEGIN
3-
CREATE UNIQUE INDEX IF NOT EXISTS "documents_slug_user_id_unique" ON "documents" ("slug","user_id") WHERE "slug" IS NOT NULL;
4-
EXCEPTION
5-
WHEN duplicate_object THEN null;
6-
END $$;
2+
CREATE UNIQUE INDEX IF NOT EXISTS "documents_slug_user_id_unique" ON "documents" USING btree ("slug","user_id") WHERE "documents"."slug" is not null;

packages/database/migrations/meta/0047_snapshot.json

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
},
77
"dialect": "postgresql",
88
"enums": {},
9-
"id": "8a423b68-c609-44e1-bd48-f2ed62fec5ef",
9+
"id": "20a4c30c-04f0-4993-b493-0ae6a3144f9e",
1010
"policies": {},
1111
"prevId": "abe0cb47-a970-4ec0-a29f-1afa9bd2fe02",
1212
"roles": {},
@@ -1259,6 +1259,12 @@
12591259
"primaryKey": false,
12601260
"notNull": false
12611261
},
1262+
"slug": {
1263+
"name": "slug",
1264+
"type": "varchar(255)",
1265+
"primaryKey": false,
1266+
"notNull": false
1267+
},
12621268
"accessed_at": {
12631269
"name": "accessed_at",
12641270
"type": "timestamp with time zone",
@@ -1362,6 +1368,28 @@
13621368
"concurrently": false,
13631369
"method": "btree",
13641370
"with": {}
1371+
},
1372+
"documents_slug_user_id_unique": {
1373+
"name": "documents_slug_user_id_unique",
1374+
"columns": [
1375+
{
1376+
"expression": "slug",
1377+
"isExpression": false,
1378+
"asc": true,
1379+
"nulls": "last"
1380+
},
1381+
{
1382+
"expression": "user_id",
1383+
"isExpression": false,
1384+
"asc": true,
1385+
"nulls": "last"
1386+
}
1387+
],
1388+
"isUnique": true,
1389+
"where": "\"documents\".\"slug\" is not null",
1390+
"concurrently": false,
1391+
"method": "btree",
1392+
"with": {}
13651393
}
13661394
},
13671395
"foreignKeys": {
@@ -1481,12 +1509,6 @@
14811509
"primaryKey": false,
14821510
"notNull": false
14831511
},
1484-
"slug": {
1485-
"name": "slug",
1486-
"type": "text",
1487-
"primaryKey": false,
1488-
"notNull": false
1489-
},
14901512
"accessed_at": {
14911513
"name": "accessed_at",
14921514
"type": "timestamp with time zone",
@@ -1610,13 +1632,7 @@
16101632
}
16111633
},
16121634
"compositePrimaryKeys": {},
1613-
"uniqueConstraints": {
1614-
"files_slug_unique": {
1615-
"name": "files_slug_unique",
1616-
"nullsNotDistinct": false,
1617-
"columns": ["slug"]
1618-
}
1619-
},
1635+
"uniqueConstraints": {},
16201636
"policies": {},
16211637
"checkConstraints": {},
16221638
"isRLSEnabled": false

packages/database/migrations/meta/_journal.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
{
334334
"idx": 47,
335335
"version": "7",
336-
"when": 1763535087148,
336+
"when": 1763987922211,
337337
"tag": "0047_add_slug_document",
338338
"breakpoints": true
339339
}

packages/database/src/core/migrations.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@
792792
{
793793
"sql": [
794794
"ALTER TABLE \"documents\" ADD COLUMN IF NOT EXISTS \"slug\" varchar(255);",
795-
"\nDO $$ BEGIN\n CREATE UNIQUE INDEX IF NOT EXISTS \"documents_slug_user_id_unique\" ON \"documents\" (\"slug\",\"user_id\") WHERE \"slug\" IS NOT NULL;\nEXCEPTION\n WHEN duplicate_object THEN null;\nEND $$;"
795+
"\nCREATE UNIQUE INDEX IF NOT EXISTS \"documents_slug_user_id_unique\" ON \"documents\" USING btree (\"slug\",\"user_id\") WHERE \"documents\".\"slug\" is not null;\n"
796796
],
797797
"bps": true,
798-
"folderMillis": 1763535087148,
799-
"hash": "57a82ce14d96ffa9f140ff63f00af994e91a74703f4d2378286e36be259f117b"
798+
"folderMillis": 1763987922211,
799+
"hash": "f823b521f4d25e5dc5ab238b372727d2d2d7f0aed27b5eabc8a9608ce4e50568"
800800
}
801801
]

0 commit comments

Comments
 (0)