Skip to content

Commit 6798f86

Browse files
authored
♻️ refactor: add client id for all core entities in database (lobehub#7089)
* add client id for all entities * add client db repair feature * update i18n
1 parent 8b761a4 commit 6798f86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+7723
-301
lines changed

docs/developer/database-schema.dbml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ table agents {
77
avatar text
88
background_color text
99
plugins jsonb [default: `[]`]
10+
client_id text
1011
user_id text [not null]
1112
chat_config jsonb
1213
few_shots jsonb
@@ -18,6 +19,10 @@ table agents {
1819
accessed_at "timestamp with time zone" [not null, default: `now()`]
1920
created_at "timestamp with time zone" [not null, default: `now()`]
2021
updated_at "timestamp with time zone" [not null, default: `now()`]
22+
23+
indexes {
24+
(client_id, user_id) [name: 'client_id_user_id_unique', unique]
25+
}
2126
}
2227

2328
table agents_files {
@@ -116,6 +121,7 @@ table files {
116121
name text [not null]
117122
size integer [not null]
118123
url text [not null]
124+
client_id text
119125
metadata jsonb
120126
chunk_task_id uuid
121127
embedding_task_id uuid
@@ -125,6 +131,7 @@ table files {
125131

126132
indexes {
127133
file_hash [name: 'file_hash_idx']
134+
(client_id, user_id) [name: 'files_client_id_user_id_unique', unique]
128135
}
129136
}
130137

@@ -157,11 +164,16 @@ table knowledge_bases {
157164
avatar text
158165
type text
159166
user_id text [not null]
167+
client_id text
160168
is_public boolean [default: false]
161169
settings jsonb
162170
accessed_at "timestamp with time zone" [not null, default: `now()`]
163171
created_at "timestamp with time zone" [not null, default: `now()`]
164172
updated_at "timestamp with time zone" [not null, default: `now()`]
173+
174+
indexes {
175+
(client_id, user_id) [name: 'knowledge_bases_client_id_user_id_unique', unique]
176+
}
165177
}
166178

167179
table message_chunks {
@@ -183,16 +195,26 @@ table message_plugins {
183195
identifier text
184196
state jsonb
185197
error jsonb
198+
client_id text
186199
user_id text [not null]
200+
201+
indexes {
202+
(client_id, user_id) [name: 'message_plugins_client_id_user_id_unique', unique]
203+
}
187204
}
188205

189206
table message_queries {
190207
id uuid [pk, not null, default: `gen_random_uuid()`]
191208
message_id text [not null]
192209
rewrite_query text
193210
user_query text
211+
client_id text
194212
user_id text [not null]
195213
embeddings_id uuid
214+
215+
indexes {
216+
(client_id, user_id) [name: 'message_queries_client_id_user_id_unique', unique]
217+
}
196218
}
197219

198220
table message_query_chunks {
@@ -212,15 +234,25 @@ table message_tts {
212234
content_md5 text
213235
file_id text
214236
voice text
237+
client_id text
215238
user_id text [not null]
239+
240+
indexes {
241+
(client_id, user_id) [name: 'message_tts_client_id_user_id_unique', unique]
242+
}
216243
}
217244

218245
table message_translates {
219246
id text [pk, not null]
220247
content text
221248
from text
222249
to text
250+
client_id text
223251
user_id text [not null]
252+
253+
indexes {
254+
(client_id, user_id) [name: 'message_translates_client_id_user_id_unique', unique]
255+
}
224256
}
225257

226258
table messages {
@@ -324,18 +356,28 @@ table chunks {
324356
metadata jsonb
325357
index integer
326358
type varchar
359+
client_id text
327360
user_id text
328361
accessed_at "timestamp with time zone" [not null, default: `now()`]
329362
created_at "timestamp with time zone" [not null, default: `now()`]
330363
updated_at "timestamp with time zone" [not null, default: `now()`]
364+
365+
indexes {
366+
(client_id, user_id) [name: 'chunks_client_id_user_id_unique', unique]
367+
}
331368
}
332369

333370
table embeddings {
334371
id uuid [pk, not null, default: `gen_random_uuid()`]
335372
chunk_id uuid [unique]
336373
embeddings vector(1024)
337374
model text
375+
client_id text
338376
user_id text
377+
378+
indexes {
379+
(client_id, user_id) [name: 'embeddings_client_id_user_id_unique', unique]
380+
}
339381
}
340382

341383
table unstructured_chunks {
@@ -349,8 +391,13 @@ table unstructured_chunks {
349391
updated_at "timestamp with time zone" [not null, default: `now()`]
350392
parent_id varchar
351393
composite_id uuid
394+
client_id text
352395
user_id text
353396
file_id varchar
397+
398+
indexes {
399+
(client_id, user_id) [name: 'unstructured_chunks_client_id_user_id_unique', unique]
400+
}
354401
}
355402

356403
table rag_eval_dataset_records {
@@ -456,7 +503,7 @@ table session_groups {
456503
updated_at "timestamp with time zone" [not null, default: `now()`]
457504

458505
indexes {
459-
(client_id, user_id) [name: 'session_group_client_id_user_unique', unique]
506+
(client_id, user_id) [name: 'session_groups_client_id_user_id_unique', unique]
460507
}
461508
}
462509

@@ -490,11 +537,16 @@ table threads {
490537
topic_id text [not null]
491538
source_message_id text [not null]
492539
parent_thread_id text
540+
client_id text
493541
user_id text [not null]
494542
last_active_at "timestamp with time zone" [default: `now()`]
495543
accessed_at "timestamp with time zone" [not null, default: `now()`]
496544
created_at "timestamp with time zone" [not null, default: `now()`]
497545
updated_at "timestamp with time zone" [not null, default: `now()`]
546+
547+
indexes {
548+
(client_id, user_id) [name: 'threads_client_id_user_id_unique', unique]
549+
}
498550
}
499551

500552
table topics {
@@ -511,7 +563,7 @@ table topics {
511563
updated_at "timestamp with time zone" [not null, default: `now()`]
512564

513565
indexes {
514-
(client_id, user_id) [name: 'topic_client_id_user_id_unique', unique]
566+
(client_id, user_id) [name: 'topics_client_id_user_id_unique', unique]
515567
}
516568
}
517569

locales/ar/common.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
"error": {
4242
"desc": "نعتذر، حدث خطأ أثناء عملية تهيئة قاعدة بيانات Pglite. يرجى النقر على الزر لإعادة المحاولة. إذا استمرت المشكلة بعد عدة محاولات، يرجى <1>تقديم مشكلة</1>، وسنساعدك في حلها في أسرع وقت ممكن",
4343
"detail": "سبب الخطأ: [{{type}}] {{message}}، التفاصيل كالتالي:",
44+
"detailTitle": "سبب الخطأ",
45+
"report": "الإبلاغ عن مشكلة",
4446
"retry": "إعادة المحاولة",
47+
"selfSolve": "حل ذاتي",
4548
"title": "فشل تهيئة قاعدة البيانات"
4649
},
4750
"initing": {
@@ -80,6 +83,54 @@
8083
"button": "استخدم الآن",
8184
"desc": "استخدم الآن",
8285
"title": "قاعدة بيانات PGlite جاهزة"
86+
},
87+
"solve": {
88+
"backup": {
89+
"backup": "نسخ احتياطي",
90+
"backupSuccess": "تم النسخ الاحتياطي بنجاح",
91+
"desc": "تصدير البيانات الأساسية من قاعدة البيانات الحالية",
92+
"export": "تصدير جميع البيانات",
93+
"exportDesc": "سيتم حفظ البيانات المصدرة بتنسيق JSON، ويمكن استخدامها لاستعادة أو تحليل لاحق.",
94+
"reset": {
95+
"alert": "تحذير",
96+
"alertDesc": "قد تؤدي العمليات التالية إلى فقدان البيانات. يرجى التأكد من أنك قد قمت بعمل نسخة احتياطية من البيانات الهامة قبل المتابعة.",
97+
"button": "إعادة تعيين قاعدة البيانات بالكامل (حذف جميع البيانات)",
98+
"confirm": {
99+
"desc": "ستؤدي هذه العملية إلى حذف جميع البيانات ولا يمكن التراجع عنها، هل تؤكد المتابعة؟",
100+
"title": "تأكيد إعادة تعيين قاعدة البيانات"
101+
},
102+
"desc": "إعادة تعيين قاعدة البيانات في حالة عدم إمكانية الاستعادة",
103+
"title": "إعادة تعيين قاعدة البيانات"
104+
},
105+
"restore": "استعادة",
106+
"restoreSuccess": "تم الاستعادة بنجاح",
107+
"title": "نسخ احتياطي للبيانات"
108+
},
109+
"diagnosis": {
110+
"createdAt": "تاريخ الإنشاء",
111+
"migratedAt": "تاريخ اكتمال النقل",
112+
"sql": "نقل SQL",
113+
"title": "حالة النقل"
114+
},
115+
"repair": {
116+
"desc": "إدارة حالة النقل يدويًا",
117+
"runSQL": "تنفيذ مخصص",
118+
"sql": {
119+
"clear": "مسح",
120+
"desc": "تنفيذ عبارة SQL مخصصة لإصلاح مشاكل قاعدة البيانات",
121+
"markFinished": "تحديد كمنتهية",
122+
"placeholder": "أدخل عبارة SQL...",
123+
"result": "نتيجة التنفيذ",
124+
"run": "تنفيذ",
125+
"title": "منفذ SQL"
126+
},
127+
"title": "تحكم النقل"
128+
},
129+
"tabs": {
130+
"backup": "نسخ احتياطي واستعادة",
131+
"diagnosis": "تشخيص",
132+
"repair": "إصلاح"
133+
}
83134
}
84135
},
85136
"close": "إغلاق",

0 commit comments

Comments
 (0)