Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix: fix db migration snapshot not align with db schema (#10399)

Arvin Xu760105adb27a
diff --git a/docs/development/database-schema.dbml b/docs/development/database-schema.dbml
index 1d2c9c8b8ae..04c3a7e5d82 100644
--- a/docs/development/database-schema.dbml
+++ b/docs/development/database-schema.dbml
@@ -187,6 +187,7 @@ table documents {
user_id text [not null]
client_id text
editor_data jsonb
+ slug varchar(255)
accessed_at "timestamp with time zone" [not null, default: `now()`]
created_at "timestamp with time zone" [not null, default: `now()`]
updated_at "timestamp with time zone" [not null, default: `now()`]
@@ -197,6 +198,7 @@ table documents {
file_id [name: 'documents_file_id_idx']
parent_id [name: 'documents_parent_id_idx']
(client_id, user_id) [name: 'documents_client_id_user_id_unique', unique]
+ (slug, user_id) [name: 'documents_slug_user_id_unique', unique]
}
}
@@ -214,7 +216,6 @@ table files {
metadata jsonb
chunk_task_id uuid
embedding_task_id uuid
- slug text [unique]
accessed_at "timestamp with time zone" [not null, default: `now()`]
created_at "timestamp with time zone" [not null, default: `now()`]
updated_at "timestamp with time zone" [not null, default: `now()`]
diff --git a/packages/database/migrations/0047_add_slug_document.sql b/packages/database/migrations/0047_add_slug_document.sql
index c0737d146b5..fd867ea5d53 100644
--- a/packages/database/migrations/0047_add_slug_document.sql
+++ b/packages/database/migrations/0047_add_slug_document.sql
@@ -1,6 +1,2 @@
ALTER TABLE "documents" ADD COLUMN IF NOT EXISTS "slug" varchar(255);--> statement-breakpoint
-DO $$ BEGIN
- CREATE UNIQUE INDEX IF NOT EXISTS "documents_slug_user_id_unique" ON "documents" ("slug","user_id") WHERE "slug" IS NOT NULL;
-EXCEPTION
- WHEN duplicate_object THEN null;
-END $$;
\ No newline at end of file
+CREATE UNIQUE INDEX IF NOT EXISTS "documents_slug_user_id_unique" ON "documents" USING btree ("slug","user_id") WHERE "documents"."slug" is not null;
diff --git a/packages/database/migrations/meta/0047_snapshot.json b/packages/database/migrations/meta/0047_snapshot.json
index 8b1e4ce78bc..9d23353c94f 100644
--- a/packages/database/migrations/meta/0047_snapshot.json
+++ b/packages/database/migrations/meta/0047_snapshot.json
@@ -6,7 +6,7 @@
},
"dialect": "postgresql",
"enums": {},
- "id": "8a423b68-c609-44e1-bd48-f2ed62fec5ef",
+ "id": "20a4c30c-04f0-4993-b493-0ae6a3144f9e",
"policies": {},
"prevId": "abe0cb47-a970-4ec0-a29f-1afa9bd2fe02",
"roles": {},
@@ -1259,6 +1259,12 @@
"primaryKey": false,
"notNull": false
},
+ "slug": {
+ "name": "slug",
+ "type": "varchar(255)",
+ "primaryKey": false,
+ "notNull": false
+ },
"accessed_at": {
"name": "accessed_at",
"type": "timestamp with time zone",
@@ -1362,6 +1368,28 @@
"concurrently": false,
"method": "btree",
"with": {}
+ },
+ "documents_slug_user_id_unique": {
+ "name": "documents_slug_user_id_unique",
+ "columns": [
+ {
+ "expression": "slug",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"documents\".\"slug\" is not null",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
}
},
"foreignKeys": {
@@ -1481,12 +1509,6 @@
"primaryKey": false,
"notNull": false
},
- "slug": {
- "name": "slug",
- "type": "text",
- "primaryKey": false,
- "notNull": false
- },
"accessed_at": {
"name": "accessed_at",
"type": "timestamp with time zone",
@@ -1610,13 +1632,7 @@
}
},
"compositePrimaryKeys": {},
- "uniqueConstraints": {
- "files_slug_unique": {
- "name": "files_slug_unique",
- "nullsNotDistinct": false,
- "columns": ["slug"]
- }
- },
+ "uniqueConstraints": {},
"policies": {},
"checkConstraints": {},
"isRLSEnabled": false
diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.json
index 78ea6b4dcf4..28339f90833 100644
--- a/packages/database/migrations/meta/_journal.json
+++ b/packages/database/migrations/meta/_journal.json
@@ -333,7 +333,7 @@
{
"idx": 47,
"version": "7",
- "when": 1763535087148,
+ "when": 1763987922211,
"tag": "0047_add_slug_document",
"breakpoints": true
}
diff --git a/packages/database/src/core/migrations.json b/packages/database/src/core/migrations.json
index 15f6181a85f..de7727316a0 100644
--- a/packages/database/src/core/migrations.json
+++ b/packages/database/src/core/migrations.json
@@ -792,10 +792,10 @@
{
"sql": [
"ALTER TABLE \"documents\" ADD COLUMN IF NOT EXISTS \"slug\" varchar(255);",
- "\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 $$;"
+ "\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"
],
"bps": true,
- "folderMillis": 1763535087148,
- "hash": "57a82ce14d96ffa9f140ff63f00af994e91a74703f4d2378286e36be259f117b"
+ "folderMillis": 1763987922211,
+ "hash": "f823b521f4d25e5dc5ab238b372727d2d2d7f0aed27b5eabc8a9608ce4e50568"
}
]