@allbluecn/database 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/generated/browser.ts +10 -0
  2. package/generated/client.ts +10 -0
  3. package/generated/internal/class.ts +24 -4
  4. package/generated/internal/prismaNamespace.ts +182 -1
  5. package/generated/internal/prismaNamespaceBrowser.ts +31 -0
  6. package/generated/models/KnowledgeBase.ts +158 -0
  7. package/generated/models/KnowledgeDocument.ts +176 -0
  8. package/generated/models/User.ts +634 -0
  9. package/generated/models/Workspace.ts +380 -0
  10. package/generated/models/WorkspaceKnowledgeBase.ts +1430 -0
  11. package/generated/models/WorkspaceQuickDoc.ts +2030 -0
  12. package/generated/models.ts +2 -0
  13. package/generated-sqlite/browser.ts +10 -0
  14. package/generated-sqlite/client.ts +10 -0
  15. package/generated-sqlite/internal/class.ts +24 -4
  16. package/generated-sqlite/internal/prismaNamespace.ts +182 -1
  17. package/generated-sqlite/internal/prismaNamespaceBrowser.ts +31 -0
  18. package/generated-sqlite/models/KnowledgeBase.ts +150 -0
  19. package/generated-sqlite/models/KnowledgeDocument.ts +168 -0
  20. package/generated-sqlite/models/User.ts +518 -0
  21. package/generated-sqlite/models/Workspace.ts +300 -0
  22. package/generated-sqlite/models/WorkspaceKnowledgeBase.ts +1426 -0
  23. package/generated-sqlite/models/WorkspaceQuickDoc.ts +2025 -0
  24. package/generated-sqlite/models.ts +2 -0
  25. package/migrations/20260909070745_workspace_kb_card/migration.sql +55 -0
  26. package/migrations/20260909123637_workspace_quick_doc_column_index/migration.sql +2 -0
  27. package/migrations/20260909123656_workspace_quick_doc_column_backfill/migration.sql +4 -0
  28. package/migrations/20260909144328_workspace_quick_doc_label/migration.sql +2 -0
  29. package/migrations/20260909154315_workspace_quick_doc_icon/migration.sql +2 -0
  30. package/package.json +2 -2
  31. package/schema.prisma +48 -2
  32. package/schema.sqlite.prisma +48 -2
@@ -28,6 +28,8 @@ export type * from './models/InvitationUse.ts'
28
28
  export type * from './models/PasswordResetToken.ts'
29
29
  export type * from './models/KnowledgeBase.ts'
30
30
  export type * from './models/ProjectKnowledgeBase.ts'
31
+ export type * from './models/WorkspaceKnowledgeBase.ts'
32
+ export type * from './models/WorkspaceQuickDoc.ts'
31
33
  export type * from './models/KnowledgeDocument.ts'
32
34
  export type * from './models/PRD.ts'
33
35
  export type * from './models/AgentConversation.ts'
@@ -0,0 +1,55 @@
1
+ -- CreateTable
2
+ CREATE TABLE "workspace_knowledge_bases" (
3
+ "id" TEXT NOT NULL,
4
+ "workspaceId" TEXT NOT NULL,
5
+ "kbId" TEXT NOT NULL,
6
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7
+
8
+ CONSTRAINT "workspace_knowledge_bases_pkey" PRIMARY KEY ("id")
9
+ );
10
+
11
+ -- CreateTable
12
+ CREATE TABLE "workspace_quick_docs" (
13
+ "id" TEXT NOT NULL,
14
+ "workspaceId" TEXT NOT NULL,
15
+ "docId" TEXT,
16
+ "externalGroup" TEXT,
17
+ "externalId" TEXT,
18
+ "displayTitle" TEXT NOT NULL,
19
+ "sortOrder" INTEGER NOT NULL DEFAULT 0,
20
+ "createdBy" TEXT NOT NULL,
21
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22
+ "updatedAt" TIMESTAMP(3) NOT NULL,
23
+
24
+ CONSTRAINT "workspace_quick_docs_pkey" PRIMARY KEY ("id")
25
+ );
26
+
27
+ -- CreateIndex
28
+ CREATE INDEX "workspace_knowledge_bases_workspaceId_idx" ON "workspace_knowledge_bases"("workspaceId");
29
+
30
+ -- CreateIndex
31
+ CREATE INDEX "workspace_knowledge_bases_kbId_idx" ON "workspace_knowledge_bases"("kbId");
32
+
33
+ -- CreateIndex
34
+ CREATE UNIQUE INDEX "workspace_knowledge_bases_workspaceId_kbId_key" ON "workspace_knowledge_bases"("workspaceId", "kbId");
35
+
36
+ -- CreateIndex
37
+ CREATE INDEX "workspace_quick_docs_workspaceId_idx" ON "workspace_quick_docs"("workspaceId");
38
+
39
+ -- CreateIndex
40
+ CREATE INDEX "workspace_quick_docs_workspaceId_docId_idx" ON "workspace_quick_docs"("workspaceId", "docId");
41
+
42
+ -- AddForeignKey
43
+ ALTER TABLE "workspace_knowledge_bases" ADD CONSTRAINT "workspace_knowledge_bases_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE CASCADE ON UPDATE CASCADE;
44
+
45
+ -- AddForeignKey
46
+ ALTER TABLE "workspace_knowledge_bases" ADD CONSTRAINT "workspace_knowledge_bases_kbId_fkey" FOREIGN KEY ("kbId") REFERENCES "knowledge_bases"("id") ON DELETE CASCADE ON UPDATE CASCADE;
47
+
48
+ -- AddForeignKey
49
+ ALTER TABLE "workspace_quick_docs" ADD CONSTRAINT "workspace_quick_docs_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "workspaces"("id") ON DELETE CASCADE ON UPDATE CASCADE;
50
+
51
+ -- AddForeignKey
52
+ ALTER TABLE "workspace_quick_docs" ADD CONSTRAINT "workspace_quick_docs_docId_fkey" FOREIGN KEY ("docId") REFERENCES "knowledge_documents"("id") ON DELETE CASCADE ON UPDATE CASCADE;
53
+
54
+ -- AddForeignKey
55
+ ALTER TABLE "workspace_quick_docs" ADD CONSTRAINT "workspace_quick_docs_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "workspace_quick_docs" ADD COLUMN "columnIndex" INTEGER NOT NULL DEFAULT 0;
@@ -0,0 +1,4 @@
1
+ -- 看板化回填:旧模型按 sortOrder % 5 轮转分列,迁移后按此初始化列归属
2
+ UPDATE "workspace_quick_docs"
3
+ SET "columnIndex" = "sortOrder" % 5
4
+ WHERE "columnIndex" = 0 AND "sortOrder" % 5 <> 0;
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "workspace_quick_docs" ADD COLUMN "label" TEXT;
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "workspace_quick_docs" ADD COLUMN "icon" TEXT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbluecn/database",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "pg": "^8.22.0",
16
16
  "sqlite-vec": "^0.1.9",
17
17
  "bcryptjs": "^3.0.2",
18
- "@allbluecn/kernel": "0.6.0"
18
+ "@allbluecn/kernel": "0.6.1"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/better-sqlite3": "^7.6.13",
package/schema.prisma CHANGED
@@ -114,6 +114,7 @@ model User {
114
114
  ssoMappings SsoMapping[]
115
115
  roleAssignments RoleAssignment[]
116
116
  subscription Subscription?
117
+ createdQuickDocs WorkspaceQuickDoc[]
117
118
 
118
119
  @@map("users")
119
120
  }
@@ -194,8 +195,10 @@ model Workspace {
194
195
  owner User @relation("workspaceOwner", fields: [ownerId], references: [id])
195
196
  projects Project[]
196
197
  members WorkspaceMember[]
197
- knowledgeBases KnowledgeBase[]
198
- usageRecords UsageRecord[]
198
+ knowledgeBases KnowledgeBase[]
199
+ workspaceKbLinks WorkspaceKnowledgeBase[]
200
+ quickDocs WorkspaceQuickDoc[]
201
+ usageRecords UsageRecord[]
199
202
  aiUsageLogs AiUsageLog[]
200
203
  createdAt DateTime @default(now())
201
204
  updatedAt DateTime @updatedAt
@@ -513,6 +516,7 @@ model KnowledgeBase {
513
516
  workspace Workspace? @relation(fields: [workspaceId], references: [id], onDelete: SetNull)
514
517
  documents KnowledgeDocument[]
515
518
  projectLinks ProjectKnowledgeBase[]
519
+ workspaceLinks WorkspaceKnowledgeBase[]
516
520
 
517
521
  @@index([userId])
518
522
  @@index([workspaceId])
@@ -541,6 +545,7 @@ model KnowledgeDocument {
541
545
  children KnowledgeDocument[] @relation("DocumentTree")
542
546
  creator User @relation(fields: [createdBy], references: [id], onDelete: Cascade)
543
547
  linkedStories StoryDocLink[] @relation("DocStoryLinks")
548
+ workspaceQuickDocs WorkspaceQuickDoc[]
544
549
 
545
550
  @@index([kbId])
546
551
  @@index([parentId])
@@ -1590,6 +1595,47 @@ model ProjectKnowledgeBase {
1590
1595
  @@map("project_knowledge_bases")
1591
1596
  }
1592
1597
 
1598
+ // 工作空间关联知识库(join 表;仅允许 visibility=team)
1599
+ model WorkspaceKnowledgeBase {
1600
+ id String @id @default(cuid())
1601
+ workspaceId String
1602
+ kbId String
1603
+ createdAt DateTime @default(now())
1604
+
1605
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
1606
+ kb KnowledgeBase @relation(fields: [kbId], references: [id], onDelete: Cascade)
1607
+
1608
+ @@unique([workspaceId, kbId])
1609
+ @@index([workspaceId])
1610
+ @@index([kbId])
1611
+ @@map("workspace_knowledge_bases")
1612
+ }
1613
+
1614
+ // 工作空间快捷文档(单表双轨:docId 或 externalGroup+externalId 二选一非空,serverFn 层校验)
1615
+ model WorkspaceQuickDoc {
1616
+ id String @id @default(cuid())
1617
+ workspaceId String
1618
+ docId String?
1619
+ externalGroup String?
1620
+ externalId String?
1621
+ displayTitle String
1622
+ columnIndex Int @default(0)
1623
+ sortOrder Int @default(0)
1624
+ label String?
1625
+ icon String?
1626
+ createdBy String
1627
+ createdAt DateTime @default(now())
1628
+ updatedAt DateTime @updatedAt
1629
+
1630
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
1631
+ doc KnowledgeDocument? @relation(fields: [docId], references: [id], onDelete: Cascade)
1632
+ creator User @relation(fields: [createdBy], references: [id], onDelete: Cascade)
1633
+
1634
+ @@index([workspaceId])
1635
+ @@index([workspaceId, docId])
1636
+ @@map("workspace_quick_docs")
1637
+ }
1638
+
1593
1639
  model StoryLink {
1594
1640
  id String @id @default(cuid())
1595
1641
  storyId String
@@ -102,6 +102,7 @@ model User {
102
102
  agents UserAgent[]
103
103
  skills UserSkill[]
104
104
  subscription Subscription?
105
+ createdQuickDocs WorkspaceQuickDoc[]
105
106
 
106
107
  @@map("users")
107
108
  }
@@ -159,6 +160,8 @@ model Workspace {
159
160
  ownerId String
160
161
  owner User @relation("workspaceOwner", fields: [ownerId], references: [id])
161
162
  projects Project[]
163
+ workspaceKbLinks WorkspaceKnowledgeBase[]
164
+ quickDocs WorkspaceQuickDoc[]
162
165
  usageRecords UsageRecord[]
163
166
  aiUsageLogs AiUsageLog[]
164
167
  createdAt DateTime @default(now())
@@ -410,9 +413,10 @@ model KnowledgeBase {
410
413
 
411
414
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
412
415
  documents KnowledgeDocument[]
413
- projectLinks ProjectKnowledgeBase[]
416
+ projectLinks ProjectKnowledgeBase[]
417
+ workspaceLinks WorkspaceKnowledgeBase[]
414
418
 
415
- @@index([userId])
419
+ @@index([userId])
416
420
  @@map("knowledge_bases")
417
421
  }
418
422
 
@@ -432,6 +436,47 @@ model ProjectKnowledgeBase {
432
436
  @@map("project_knowledge_bases")
433
437
  }
434
438
 
439
+ // 工作空间关联知识库(join 表;仅允许 visibility=team)
440
+ model WorkspaceKnowledgeBase {
441
+ id String @id @default(cuid())
442
+ workspaceId String
443
+ kbId String
444
+ createdAt DateTime @default(now())
445
+
446
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
447
+ kb KnowledgeBase @relation(fields: [kbId], references: [id], onDelete: Cascade)
448
+
449
+ @@unique([workspaceId, kbId])
450
+ @@index([workspaceId])
451
+ @@index([kbId])
452
+ @@map("workspace_knowledge_bases")
453
+ }
454
+
455
+ // 工作空间快捷文档(单表双轨:docId 或 externalGroup+externalId 二选一非空,serverFn 层校验)
456
+ model WorkspaceQuickDoc {
457
+ id String @id @default(cuid())
458
+ workspaceId String
459
+ docId String?
460
+ externalGroup String?
461
+ externalId String?
462
+ displayTitle String
463
+ columnIndex Int @default(0)
464
+ sortOrder Int @default(0)
465
+ label String?
466
+ icon String?
467
+ createdBy String
468
+ createdAt DateTime @default(now())
469
+ updatedAt DateTime @updatedAt
470
+
471
+ workspace Workspace @relation(fields: [workspaceId], references: [id], onDelete: Cascade)
472
+ doc KnowledgeDocument? @relation(fields: [docId], references: [id], onDelete: Cascade)
473
+ creator User @relation(fields: [createdBy], references: [id], onDelete: Cascade)
474
+
475
+ @@index([workspaceId])
476
+ @@index([workspaceId, docId])
477
+ @@map("workspace_quick_docs")
478
+ }
479
+
435
480
  model KnowledgeDocument {
436
481
  id String @id @default(cuid())
437
482
  kbId String
@@ -453,6 +498,7 @@ model KnowledgeDocument {
453
498
  parent KnowledgeDocument? @relation("DocumentTree", fields: [parentId], references: [id], onDelete: SetNull)
454
499
  children KnowledgeDocument[] @relation("DocumentTree")
455
500
  creator User @relation(fields: [createdBy], references: [id], onDelete: Cascade)
501
+ workspaceQuickDocs WorkspaceQuickDoc[]
456
502
 
457
503
  @@index([kbId])
458
504
  @@index([parentId])