@varaos/db 1.5.0 → 1.5.2

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varaos/db",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,37 @@
1
+ -- AlterTable: Add currentVersion to WorkflowTemplate
2
+ ALTER TABLE "WorkflowTemplate" ADD COLUMN "currentVersion" INTEGER NOT NULL DEFAULT 1;
3
+
4
+ -- CreateTable: WorkflowTemplateVersion
5
+ CREATE TABLE "WorkflowTemplateVersion" (
6
+ "id" TEXT NOT NULL,
7
+ "templateId" TEXT NOT NULL,
8
+ "version" INTEGER NOT NULL,
9
+ "name" TEXT NOT NULL,
10
+ "description" TEXT,
11
+ "category" TEXT,
12
+ "recommended" BOOLEAN NOT NULL DEFAULT false,
13
+ "iconUrl" TEXT,
14
+ "estimatedSetupTime" INTEGER,
15
+ "spec" JSONB,
16
+ "triggerType" "public"."TriggerType",
17
+ "triggerConfig" JSONB,
18
+ "requiredIntegrations" TEXT[] DEFAULT ARRAY[]::TEXT[],
19
+ "requiredInputs" JSONB,
20
+ "setupTokenCost" INTEGER NOT NULL DEFAULT 0,
21
+ "runTokenCost" INTEGER NOT NULL DEFAULT 10,
22
+ "steps" JSONB NOT NULL,
23
+ "changeNote" TEXT,
24
+ "createdBy" TEXT,
25
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26
+
27
+ CONSTRAINT "WorkflowTemplateVersion_pkey" PRIMARY KEY ("id")
28
+ );
29
+
30
+ -- CreateIndex: unique constraint on (templateId, version)
31
+ CREATE UNIQUE INDEX "WorkflowTemplateVersion_templateId_version_key" ON "WorkflowTemplateVersion"("templateId", "version");
32
+
33
+ -- CreateIndex: index on templateId for fast lookups
34
+ CREATE INDEX "WorkflowTemplateVersion_templateId_idx" ON "WorkflowTemplateVersion"("templateId");
35
+
36
+ -- AddForeignKey: link to WorkflowTemplate with cascade delete
37
+ ALTER TABLE "WorkflowTemplateVersion" ADD CONSTRAINT "WorkflowTemplateVersion_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "WorkflowTemplate"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -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");
@@ -564,6 +564,7 @@ model Integration {
564
564
  accessToken String
565
565
  refreshToken String?
566
566
  expiresAt DateTime?
567
+ refreshTokenExpiresAt DateTime?
567
568
  scopes Json
568
569
  profile Json
569
570
  status IntegrationStatus @default(active)
@@ -1092,14 +1093,26 @@ model ConversationSummary {
1092
1093
  model Notification {
1093
1094
  id String @id @default(uuid())
1094
1095
  userId String?
1095
- type String
1096
+
1097
+ type String // workflow_started, workflow_completed, workflow_failed, integration_expired, system
1096
1098
  title String
1097
- body String?
1098
- read Boolean @default(false)
1099
+ body String? @db.Text
1100
+
1101
+ read Boolean @default(false)
1102
+ readAt DateTime?
1103
+
1104
+ /// Optional deep link (e.g. "/integrations/google-gmail" or "/automations/abc")
1105
+ actionUrl String?
1106
+
1107
+ metadata Json?
1099
1108
 
1100
1109
  createdAt DateTime @default(now())
1101
1110
 
1102
- user User? @relation(fields: [userId], references: [id])
1111
+ user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
1112
+
1113
+ @@index([userId, read])
1114
+ @@index([userId, createdAt])
1115
+ @@index([type])
1103
1116
  }
1104
1117
 
1105
1118
  model ChatSession {
@@ -1205,11 +1218,43 @@ model WorkflowTemplate {
1205
1218
  setupTokenCost Int @default(0) // Tokens deducted when copying template
1206
1219
  runTokenCost Int @default(10) // Expected tokens per run or per step
1207
1220
 
1221
+ /// Current version number (auto-incremented on each update)
1222
+ currentVersion Int @default(1)
1223
+
1208
1224
  createdAt DateTime @default(now())
1209
1225
  updatedAt DateTime @updatedAt
1210
1226
 
1211
- steps WorkflowStepTemplate[]
1227
+ steps WorkflowStepTemplate[]
1212
1228
  workflows Workflow[]
1229
+ versions WorkflowTemplateVersion[]
1230
+ }
1231
+
1232
+ model WorkflowTemplateVersion {
1233
+ id String @id @default(uuid())
1234
+ templateId String
1235
+ version Int
1236
+ name String
1237
+ description String?
1238
+ category String?
1239
+ recommended Boolean @default(false)
1240
+ iconUrl String?
1241
+ estimatedSetupTime Int?
1242
+ spec Json?
1243
+ triggerType TriggerType?
1244
+ triggerConfig Json?
1245
+ requiredIntegrations String[] @default([])
1246
+ requiredInputs Json?
1247
+ setupTokenCost Int @default(0)
1248
+ runTokenCost Int @default(10)
1249
+ steps Json // snapshot of WorkflowStepTemplate[] at this version
1250
+ changeNote String?
1251
+ createdBy String? // admin user email
1252
+ createdAt DateTime @default(now())
1253
+
1254
+ template WorkflowTemplate @relation(fields: [templateId], references: [id], onDelete: Cascade)
1255
+
1256
+ @@unique([templateId, version])
1257
+ @@index([templateId])
1213
1258
  }
1214
1259
 
1215
1260
  model WorkflowStepTemplate {
@@ -2092,6 +2137,7 @@ model DeadLetterJob {
2092
2137
  }
2093
2138
 
2094
2139
 
2140
+
2095
2141
  /// ─────────────────────────────────────────────────────────────
2096
2142
  /// ADMIN USER MANAGEMENT (For SaaS Admin Panel)
2097
2143
  /// ─────────────────────────────────────────────────────────────