@varaos/db 1.5.1 → 1.5.3
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.
package/package.json
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
-- Migration: add_notification_enhancements_and_refresh_token
|
|
2
|
+
-- Description:
|
|
3
|
+
-- 1. Add refreshTokenExpiresAt to Integration for proactive token expiry tracking
|
|
4
|
+
-- 2. Enhance Notification model with readAt, actionUrl, metadata, indexes
|
|
5
|
+
-- 3. Update Notification FK to CASCADE on user deletion
|
|
6
|
+
|
|
7
|
+
-- ============================================================
|
|
8
|
+
-- 1. Integration: Add refreshTokenExpiresAt
|
|
9
|
+
-- ============================================================
|
|
10
|
+
|
|
11
|
+
-- AlterTable
|
|
12
|
+
ALTER TABLE "integrations" ADD COLUMN "refreshTokenExpiresAt" TIMESTAMP(3);
|
|
13
|
+
|
|
14
|
+
-- ============================================================
|
|
15
|
+
-- 2. Notification: Add new columns
|
|
16
|
+
-- ============================================================
|
|
17
|
+
|
|
18
|
+
-- AlterTable
|
|
19
|
+
ALTER TABLE "Notification" ADD COLUMN "readAt" TIMESTAMP(3);
|
|
20
|
+
ALTER TABLE "Notification" ADD COLUMN "actionUrl" TEXT;
|
|
21
|
+
ALTER TABLE "Notification" ADD COLUMN "metadata" JSONB;
|
|
22
|
+
|
|
23
|
+
-- ============================================================
|
|
24
|
+
-- 3. Notification: Update FK to ON DELETE CASCADE
|
|
25
|
+
-- ============================================================
|
|
26
|
+
|
|
27
|
+
-- DropForeignKey (old: ON DELETE SET NULL)
|
|
28
|
+
ALTER TABLE "Notification" DROP CONSTRAINT "Notification_userId_fkey";
|
|
29
|
+
|
|
30
|
+
-- AddForeignKey (new: ON DELETE CASCADE)
|
|
31
|
+
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
32
|
+
|
|
33
|
+
-- ============================================================
|
|
34
|
+
-- 4. Notification: Add performance indexes
|
|
35
|
+
-- ============================================================
|
|
36
|
+
|
|
37
|
+
-- CreateIndex
|
|
38
|
+
CREATE INDEX "Notification_userId_read_idx" ON "Notification"("userId", "read");
|
|
39
|
+
|
|
40
|
+
-- CreateIndex
|
|
41
|
+
CREATE INDEX "Notification_userId_createdAt_idx" ON "Notification"("userId", "createdAt");
|
|
42
|
+
|
|
43
|
+
-- CreateIndex
|
|
44
|
+
CREATE INDEX "Notification_type_idx" ON "Notification"("type");
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
-- Migration: add_system_announcements
|
|
2
|
+
-- Description:
|
|
3
|
+
-- 1. Add TargetSegment enum for audience targeting
|
|
4
|
+
-- 2. Add SystemAnnouncement table for broadcast messages
|
|
5
|
+
-- 3. Add UserAnnouncementRead table for read receipts
|
|
6
|
+
|
|
7
|
+
-- ============================================================
|
|
8
|
+
-- 1. ENUM: TargetSegment
|
|
9
|
+
-- ============================================================
|
|
10
|
+
|
|
11
|
+
CREATE TYPE "TargetSegment" AS ENUM (
|
|
12
|
+
'all',
|
|
13
|
+
'free_plan',
|
|
14
|
+
'pro_plan',
|
|
15
|
+
'business',
|
|
16
|
+
'enterprise',
|
|
17
|
+
'admin'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
-- ============================================================
|
|
21
|
+
-- 2. TABLE: SystemAnnouncement
|
|
22
|
+
-- ============================================================
|
|
23
|
+
|
|
24
|
+
CREATE TABLE "SystemAnnouncement" (
|
|
25
|
+
"id" TEXT NOT NULL,
|
|
26
|
+
"title" TEXT NOT NULL,
|
|
27
|
+
"body" TEXT,
|
|
28
|
+
"type" TEXT NOT NULL,
|
|
29
|
+
"actionUrl" TEXT,
|
|
30
|
+
"targetSegment" "TargetSegment" NOT NULL DEFAULT 'all',
|
|
31
|
+
"active" BOOLEAN NOT NULL DEFAULT true,
|
|
32
|
+
"expiresAt" TIMESTAMP(3),
|
|
33
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
34
|
+
|
|
35
|
+
CONSTRAINT "SystemAnnouncement_pkey" PRIMARY KEY ("id")
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
-- ============================================================
|
|
39
|
+
-- 3. TABLE: UserAnnouncementRead
|
|
40
|
+
-- ============================================================
|
|
41
|
+
|
|
42
|
+
CREATE TABLE "UserAnnouncementRead" (
|
|
43
|
+
"id" TEXT NOT NULL,
|
|
44
|
+
"userId" TEXT NOT NULL,
|
|
45
|
+
"announcementId" TEXT NOT NULL,
|
|
46
|
+
"readAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
47
|
+
|
|
48
|
+
CONSTRAINT "UserAnnouncementRead_pkey" PRIMARY KEY ("id")
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
-- ============================================================
|
|
52
|
+
-- 4. UNIQUE CONSTRAINT
|
|
53
|
+
-- ============================================================
|
|
54
|
+
|
|
55
|
+
CREATE UNIQUE INDEX "UserAnnouncementRead_userId_announcementId_key"
|
|
56
|
+
ON "UserAnnouncementRead"("userId", "announcementId");
|
|
57
|
+
|
|
58
|
+
-- ============================================================
|
|
59
|
+
-- 5. INDEX
|
|
60
|
+
-- ============================================================
|
|
61
|
+
|
|
62
|
+
CREATE INDEX "UserAnnouncementRead_userId_idx"
|
|
63
|
+
ON "UserAnnouncementRead"("userId");
|
|
64
|
+
|
|
65
|
+
-- ============================================================
|
|
66
|
+
-- 6. FOREIGN KEYS
|
|
67
|
+
-- ============================================================
|
|
68
|
+
|
|
69
|
+
ALTER TABLE "UserAnnouncementRead"
|
|
70
|
+
ADD CONSTRAINT "UserAnnouncementRead_userId_fkey"
|
|
71
|
+
FOREIGN KEY ("userId") REFERENCES "User"("id")
|
|
72
|
+
ON DELETE CASCADE ON UPDATE CASCADE;
|
|
73
|
+
|
|
74
|
+
ALTER TABLE "UserAnnouncementRead"
|
|
75
|
+
ADD CONSTRAINT "UserAnnouncementRead_announcementId_fkey"
|
|
76
|
+
FOREIGN KEY ("announcementId") REFERENCES "SystemAnnouncement"("id")
|
|
77
|
+
ON DELETE CASCADE ON UPDATE CASCADE;
|
package/prisma/schema.prisma
CHANGED
|
@@ -307,6 +307,15 @@ enum ToolStatus {
|
|
|
307
307
|
beta
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
enum TargetSegment {
|
|
311
|
+
all // Broadcast to every active user in the system
|
|
312
|
+
free_plan // Broadcast only to users on the free plan (e.g. upselling campaigns)
|
|
313
|
+
pro_plan // Broadcast only to users on the pro plan (e.g. announcing new premium features)
|
|
314
|
+
business // Broadcast to users on the business plan
|
|
315
|
+
enterprise // Broadcast only to enterprise plan users
|
|
316
|
+
admin // Internal broadcast only for system admins and moderators
|
|
317
|
+
}
|
|
318
|
+
|
|
310
319
|
/// ─────────────────────────────────────────────
|
|
311
320
|
/// USERS & AUTH
|
|
312
321
|
/// ─────────────────────────────────────────────
|
|
@@ -564,6 +573,7 @@ model Integration {
|
|
|
564
573
|
accessToken String
|
|
565
574
|
refreshToken String?
|
|
566
575
|
expiresAt DateTime?
|
|
576
|
+
refreshTokenExpiresAt DateTime?
|
|
567
577
|
scopes Json
|
|
568
578
|
profile Json
|
|
569
579
|
status IntegrationStatus @default(active)
|
|
@@ -1092,14 +1102,55 @@ model ConversationSummary {
|
|
|
1092
1102
|
model Notification {
|
|
1093
1103
|
id String @id @default(uuid())
|
|
1094
1104
|
userId String?
|
|
1095
|
-
|
|
1105
|
+
|
|
1106
|
+
type String // workflow_started, workflow_completed, workflow_failed, integration_expired, system
|
|
1096
1107
|
title String
|
|
1097
|
-
body String?
|
|
1098
|
-
|
|
1108
|
+
body String? @db.Text
|
|
1109
|
+
|
|
1110
|
+
read Boolean @default(false)
|
|
1111
|
+
readAt DateTime?
|
|
1112
|
+
|
|
1113
|
+
/// Optional deep link (e.g. "/integrations/google-gmail" or "/automations/abc")
|
|
1114
|
+
actionUrl String?
|
|
1115
|
+
|
|
1116
|
+
metadata Json?
|
|
1099
1117
|
|
|
1100
1118
|
createdAt DateTime @default(now())
|
|
1101
1119
|
|
|
1102
|
-
user User? @relation(fields: [userId], references: [id])
|
|
1120
|
+
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
1121
|
+
|
|
1122
|
+
@@index([userId, read])
|
|
1123
|
+
@@index([userId, createdAt])
|
|
1124
|
+
@@index([type])
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
model SystemAnnouncement {
|
|
1128
|
+
id String @id @default(uuid())
|
|
1129
|
+
title String
|
|
1130
|
+
body String? @db.Text
|
|
1131
|
+
type String // e.g. 'info', 'warning', 'feature', 'maintenance'
|
|
1132
|
+
actionUrl String?
|
|
1133
|
+
|
|
1134
|
+
targetSegment TargetSegment @default(all)
|
|
1135
|
+
|
|
1136
|
+
active Boolean @default(true)
|
|
1137
|
+
expiresAt DateTime?
|
|
1138
|
+
createdAt DateTime @default(now())
|
|
1139
|
+
|
|
1140
|
+
readReceipts UserAnnouncementRead[]
|
|
1141
|
+
}
|
|
1142
|
+
|
|
1143
|
+
model UserAnnouncementRead {
|
|
1144
|
+
id String @id @default(uuid())
|
|
1145
|
+
userId String
|
|
1146
|
+
announcementId String
|
|
1147
|
+
readAt DateTime @default(now())
|
|
1148
|
+
|
|
1149
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
1150
|
+
announcement SystemAnnouncement @relation(fields: [announcementId], references: [id], onDelete: Cascade)
|
|
1151
|
+
|
|
1152
|
+
@@unique([userId, announcementId])
|
|
1153
|
+
@@index([userId])
|
|
1103
1154
|
}
|
|
1104
1155
|
|
|
1105
1156
|
model ChatSession {
|
|
@@ -2124,6 +2175,7 @@ model DeadLetterJob {
|
|
|
2124
2175
|
}
|
|
2125
2176
|
|
|
2126
2177
|
|
|
2178
|
+
|
|
2127
2179
|
/// ─────────────────────────────────────────────────────────────
|
|
2128
2180
|
/// ADMIN USER MANAGEMENT (For SaaS Admin Panel)
|
|
2129
2181
|
/// ─────────────────────────────────────────────────────────────
|