@allbluecn/database 0.4.13 → 0.4.15

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.
@@ -86,6 +86,4 @@ export type * from './models/ComplianceExport'
86
86
  export type * from './models/UserAgent'
87
87
  export type * from './models/UserSkill'
88
88
  export type * from './models/DeveloperLog'
89
- export type * from './models/Notification'
90
- export type * from './models/NotificationPreference'
91
89
  export type * from './commonInputTypes'
@@ -0,0 +1,37 @@
1
+ -- 依赖关系存储规范化(对齐 Plane):
2
+ -- 旧模型 4 值(BLOCKS / BLOCKED_BY / RELATES_TO)→ 新模型 3 正向值
3
+ -- (BLOCKS / STARTS_BEFORE / FINISHES_BEFORE),语义统一为「source 领先于 target」。
4
+ -- 本迁移需先清理数据再重建 enum,否则 USING cast 会因残留旧值失败。
5
+
6
+ -- 1. 删除 RELATES_TO(Plane 中属于 Relation,不属于依赖)
7
+ DELETE FROM "story_dependencies" WHERE "type" = 'RELATES_TO';
8
+
9
+ -- 2. 删除翻转后与现存 BLOCKS 重复的 BLOCKED_BY 行
10
+ DELETE FROM "story_dependencies" d
11
+ WHERE d."type" = 'BLOCKED_BY'
12
+ AND EXISTS (
13
+ SELECT 1 FROM "story_dependencies" b
14
+ WHERE b."type" = 'BLOCKS'
15
+ AND b."sourceId" = d."targetId"
16
+ AND b."targetId" = d."sourceId"
17
+ );
18
+
19
+ -- 3. BLOCKED_BY 翻转(X BLOCKED_BY Y ≡ Y BLOCKS X;PG UPDATE 右侧均取旧值,可直接交换)
20
+ UPDATE "story_dependencies"
21
+ SET "sourceId" = "targetId", "targetId" = "sourceId", "type" = 'BLOCKS'
22
+ WHERE "type" = 'BLOCKED_BY';
23
+
24
+ -- 4. enum 重建为 3 正向值
25
+ DO $$
26
+ BEGIN
27
+ IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'DependencyType_old') THEN
28
+ EXECUTE 'DROP TYPE "DependencyType_old"';
29
+ END IF;
30
+ END $$;
31
+
32
+ ALTER TYPE "DependencyType" RENAME TO "DependencyType_old";
33
+ CREATE TYPE "DependencyType" AS ENUM ('BLOCKS', 'STARTS_BEFORE', 'FINISHES_BEFORE');
34
+ ALTER TABLE "story_dependencies"
35
+ ALTER COLUMN "type" TYPE "DependencyType"
36
+ USING ("type"::text::"DependencyType");
37
+ DROP TYPE "DependencyType_old";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbluecn/database",
3
- "version": "0.4.13",
3
+ "version": "0.4.15",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "main": "./index.ts",
@@ -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/shared": "0.4.13"
18
+ "@allbluecn/shared": "0.4.16"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/better-sqlite3": "^7.6.13",
package/schema.prisma CHANGED
@@ -105,8 +105,8 @@ model User {
105
105
  aiUsageLogs AiUsageLog[]
106
106
  agents UserAgent[]
107
107
  skills UserSkill[]
108
- notifications Notification[]
109
- notificationPreference NotificationPreference?
108
+ notifications Notification[]
109
+ notificationPreference NotificationPreference?
110
110
 
111
111
  issuedLicenses LicenseKey[] @relation("LicenseIssuer")
112
112
  ssoMappings SsoMapping[]
@@ -1600,8 +1600,8 @@ model StoryDocLink {
1600
1600
 
1601
1601
  enum DependencyType {
1602
1602
  BLOCKS
1603
- BLOCKED_BY
1604
- RELATES_TO
1603
+ STARTS_BEFORE
1604
+ FINISHES_BEFORE
1605
1605
  }
1606
1606
 
1607
1607
  // 需求模块保存视图(per-user 私有)
@@ -2060,8 +2060,8 @@ model DeveloperLog {
2060
2060
  model Notification {
2061
2061
  id String @id @default(cuid())
2062
2062
  userId String
2063
- category String // team | collaboration | system | billing | security
2064
- type String // 细分事件类型:team.invite_request、billing.payment_failed 等
2063
+ category String
2064
+ type String
2065
2065
  title String
2066
2066
  body String?
2067
2067
  link String?
@@ -97,8 +97,6 @@ model User {
97
97
  aiUsageLogs AiUsageLog[]
98
98
  agents UserAgent[]
99
99
  skills UserSkill[]
100
- notifications Notification[]
101
- notificationPreference NotificationPreference?
102
100
  subscription Subscription?
103
101
 
104
102
  @@map("users")
@@ -1624,33 +1622,3 @@ model DeveloperLog {
1624
1622
  @@index([year, date])
1625
1623
  @@map("developer_logs")
1626
1624
  }
1627
-
1628
- // 通知(团队邀请、协作请求、系统消息等)
1629
- model Notification {
1630
- id String @id @default(cuid())
1631
- userId String
1632
- category String // team | collaboration | system | billing | security
1633
- type String // 细分事件类型:team.invite_request、billing.payment_failed 等
1634
- title String
1635
- body String?
1636
- link String?
1637
- readAt DateTime?
1638
- createdAt DateTime @default(now())
1639
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
1640
-
1641
- @@index([userId, createdAt(sort: Desc)])
1642
- @@index([userId, readAt])
1643
- @@map("notifications")
1644
- }
1645
-
1646
- // 通知偏好(免打扰时段、分类开关)
1647
- model NotificationPreference {
1648
- userId String @id
1649
- categories Json
1650
- dndEnabled Boolean @default(false)
1651
- dndStart String @default("22:00")
1652
- dndEnd String @default("08:00")
1653
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
1654
-
1655
- @@map("notification_preferences")
1656
- }