@varaos/db 1.1.2 → 1.1.4

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.1.2",
3
+ "version": "1.1.4",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "files": [
@@ -10,5 +10,8 @@
10
10
  "license": "MIT",
11
11
  "devDependencies": {
12
12
  "prisma": "^6.16.1"
13
+ },
14
+ "dependencies": {
15
+ "@prisma/client": "^6.16.1"
13
16
  }
14
17
  }
@@ -0,0 +1,80 @@
1
+ -- AlterTable
2
+ ALTER TABLE "public"."AuditLog" ADD COLUMN "actorRole" "public"."Role",
3
+ ADD COLUMN "targetId" TEXT,
4
+ ADD COLUMN "targetType" TEXT;
5
+
6
+ -- CreateTable
7
+ CREATE TABLE "public"."EmailLog" (
8
+ "id" TEXT NOT NULL,
9
+ "to" TEXT NOT NULL,
10
+ "subject" TEXT NOT NULL,
11
+ "type" TEXT NOT NULL,
12
+ "status" TEXT NOT NULL DEFAULT 'sent',
13
+ "metadata" JSONB,
14
+ "sentAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
15
+ "error" TEXT,
16
+
17
+ CONSTRAINT "EmailLog_pkey" PRIMARY KEY ("id")
18
+ );
19
+
20
+ -- CreateTable
21
+ CREATE TABLE "public"."Service" (
22
+ "id" TEXT NOT NULL,
23
+ "name" TEXT NOT NULL,
24
+ "description" TEXT,
25
+ "endpoint" TEXT NOT NULL,
26
+ "status" TEXT NOT NULL DEFAULT 'healthy',
27
+ "lastPing" TIMESTAMP(3),
28
+ "uptime" DOUBLE PRECISION,
29
+ "region" TEXT,
30
+ "metadata" JSONB,
31
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
32
+ "updatedAt" TIMESTAMP(3) NOT NULL,
33
+
34
+ CONSTRAINT "Service_pkey" PRIMARY KEY ("id")
35
+ );
36
+
37
+ -- CreateTable
38
+ CREATE TABLE "public"."ServiceLog" (
39
+ "id" TEXT NOT NULL,
40
+ "serviceId" TEXT NOT NULL,
41
+ "level" TEXT NOT NULL,
42
+ "message" TEXT NOT NULL,
43
+ "metadata" JSONB,
44
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
45
+
46
+ CONSTRAINT "ServiceLog_pkey" PRIMARY KEY ("id")
47
+ );
48
+
49
+ -- CreateTable
50
+ CREATE TABLE "public"."ErrorLog" (
51
+ "id" TEXT NOT NULL,
52
+ "serviceId" TEXT,
53
+ "errorType" TEXT,
54
+ "message" TEXT NOT NULL,
55
+ "stackTrace" TEXT,
56
+ "context" JSONB,
57
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
58
+
59
+ CONSTRAINT "ErrorLog_pkey" PRIMARY KEY ("id")
60
+ );
61
+
62
+ -- CreateTable
63
+ CREATE TABLE "public"."SystemConfig" (
64
+ "id" TEXT NOT NULL,
65
+ "key" TEXT NOT NULL,
66
+ "value" JSONB NOT NULL,
67
+ "category" TEXT,
68
+ "updatedAt" TIMESTAMP(3) NOT NULL,
69
+
70
+ CONSTRAINT "SystemConfig_pkey" PRIMARY KEY ("id")
71
+ );
72
+
73
+ -- CreateIndex
74
+ CREATE UNIQUE INDEX "SystemConfig_key_key" ON "public"."SystemConfig"("key");
75
+
76
+ -- AddForeignKey
77
+ ALTER TABLE "public"."ServiceLog" ADD CONSTRAINT "ServiceLog_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
78
+
79
+ -- AddForeignKey
80
+ ALTER TABLE "public"."ErrorLog" ADD CONSTRAINT "ErrorLog_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "public"."Service"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,21 @@
1
+ -- AlterEnum
2
+ -- This migration adds more than one value to an enum.
3
+ -- With PostgreSQL versions 11 and earlier, this is not possible
4
+ -- in a single migration. This can be worked around by creating
5
+ -- multiple migrations, each migration adding only one value to
6
+ -- the enum.
7
+
8
+
9
+ ALTER TYPE "public"."Status" ADD VALUE 'draft';
10
+ ALTER TYPE "public"."Status" ADD VALUE 'pending_review';
11
+ ALTER TYPE "public"."Status" ADD VALUE 'deprecated';
12
+ ALTER TYPE "public"."Status" ADD VALUE 'archived';
13
+
14
+ -- DropIndex
15
+ DROP INDEX "public"."Workspace_ownerId_key";
16
+
17
+ -- CreateIndex
18
+ CREATE INDEX "AuditLog_userId_createdAt_idx" ON "public"."AuditLog"("userId", "createdAt");
19
+
20
+ -- CreateIndex
21
+ CREATE INDEX "Workspace_ownerId_idx" ON "public"."Workspace"("ownerId");
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "public"."integration_catalog" ALTER COLUMN "status" SET DEFAULT 'draft';
@@ -8,7 +8,10 @@ datasource db {
8
8
  directUrl = env("DIRECT_URL")
9
9
  }
10
10
 
11
- /// Global roles
11
+ /// ─────────────────────────────────────────────
12
+ /// ENUMS
13
+ /// ─────────────────────────────────────────────
14
+
12
15
  enum Role {
13
16
  user
14
17
  support
@@ -18,21 +21,22 @@ enum Role {
18
21
  admin
19
22
  }
20
23
 
21
- /// Common status values for most resources
22
24
  enum Status {
23
- active
24
- suspended
25
- deleted
25
+ active // Visible and usable in production
26
+ suspended // Temporarily disabled but can be restored
27
+ deleted // Soft-deleted or removed from UI
28
+ draft // Being worked on but not yet published
29
+ pending_review // Awaiting manual or automated approval
30
+ deprecated // Old but still accessible for legacy users
31
+ archived // Hidden from new users, preserved for history
26
32
  }
27
33
 
28
- /// Billing plans
29
34
  enum Plan {
30
35
  free
31
36
  pro
32
37
  enterprise
33
38
  }
34
39
 
35
- /// Chat message authors
36
40
  enum MessageRole {
37
41
  user
38
42
  assistant
@@ -41,31 +45,12 @@ enum MessageRole {
41
45
  moderator
42
46
  }
43
47
 
44
- model Workspace {
45
- id String @id @default(uuid())
46
- name String
47
- description String?
48
- ownerId String @unique
49
- status Status @default(active)
50
- deletedAt DateTime?
51
-
52
- createdAt DateTime @default(now())
53
- updatedAt DateTime @updatedAt
54
-
55
- owner User @relation("UserWorkspaces", fields: [ownerId], references: [id])
56
- defaultFor User? @relation("UserDefaultWorkspace")
57
-
58
- integrations Integration[]
59
- aiAgents AIAgent[]
60
- Workflow Workflow[]
61
- ChatSession ChatSession[]
62
-
63
- @@index([status])
64
- }
48
+ /// ─────────────────────────────────────────────
49
+ /// USERS & AUTH
50
+ /// ─────────────────────────────────────────────
65
51
 
66
52
  model User {
67
- id String @id @default(uuid())
68
-
53
+ id String @id @default(uuid())
69
54
  name String
70
55
  image String?
71
56
  email String @unique
@@ -145,6 +130,33 @@ model PasswordResetToken {
145
130
  @@unique([email, token])
146
131
  }
147
132
 
133
+ /// ─────────────────────────────────────────────
134
+ /// WORKSPACES & INTEGRATIONS
135
+ /// ─────────────────────────────────────────────
136
+
137
+ model Workspace {
138
+ id String @id @default(uuid())
139
+ name String
140
+ description String?
141
+ ownerId String
142
+ status Status @default(active)
143
+ deletedAt DateTime?
144
+
145
+ createdAt DateTime @default(now())
146
+ updatedAt DateTime @updatedAt
147
+
148
+ owner User @relation("UserWorkspaces", fields: [ownerId], references: [id])
149
+ defaultFor User? @relation("UserDefaultWorkspace")
150
+
151
+ integrations Integration[]
152
+ aiAgents AIAgent[]
153
+ Workflow Workflow[]
154
+ ChatSession ChatSession[]
155
+
156
+ @@index([status])
157
+ @@index([ownerId])
158
+ }
159
+
148
160
  model Integration {
149
161
  id String @id @default(cuid())
150
162
  userId String
@@ -188,7 +200,7 @@ model IntegrationCatalog {
188
200
  docsUrl String?
189
201
  oauthType String?
190
202
  setupInstructions Json?
191
- status Status @default(active)
203
+ status Status @default(draft)
192
204
 
193
205
  createdAt DateTime @default(now())
194
206
  updatedAt DateTime @updatedAt
@@ -208,6 +220,10 @@ model IntegrationSyncLog {
208
220
  integration Integration @relation(fields: [integrationId], references: [id])
209
221
  }
210
222
 
223
+ /// ─────────────────────────────────────────────
224
+ /// AUTOMATIONS / AI / WORKFLOWS
225
+ /// ─────────────────────────────────────────────
226
+
211
227
  model AIAgent {
212
228
  id String @id @default(uuid())
213
229
  name String
@@ -238,62 +254,6 @@ model TokenTransaction {
238
254
  agent AIAgent? @relation(fields: [agentId], references: [id])
239
255
  }
240
256
 
241
- model AuditLog {
242
- id String @id @default(uuid())
243
- userId String?
244
- eventType String
245
- description String?
246
- metadata Json?
247
- createdAt DateTime @default(now())
248
-
249
- user User? @relation(fields: [userId], references: [id])
250
- }
251
-
252
- model Subscription {
253
- id String @id @default(uuid())
254
- userId String
255
- plan Plan
256
- status String
257
- startedAt DateTime
258
- endedAt DateTime?
259
- nextPayment DateTime?
260
- metadata Json?
261
-
262
- user User @relation(fields: [userId], references: [id])
263
- }
264
-
265
- model WaitList {
266
- id String @id @default(uuid())
267
- email String @unique
268
- name String?
269
- company String?
270
- role String?
271
- teamSize String?
272
- useCase String?
273
- consentToUpdates Boolean
274
- referralCode String? @unique
275
- referredBy String?
276
-
277
- createdAt DateTime @default(now())
278
- updatedAt DateTime @updatedAt
279
- }
280
-
281
- model Job {
282
- id String @id @default(uuid())
283
- type String
284
- status String @default("pending")
285
- payload Json
286
- retries Int @default(0)
287
- maxRetries Int @default(3)
288
- error String?
289
- scheduledAt DateTime?
290
- startedAt DateTime?
291
- finishedAt DateTime?
292
-
293
- createdAt DateTime @default(now())
294
- updatedAt DateTime @updatedAt
295
- }
296
-
297
257
  model Workflow {
298
258
  id String @id @default(uuid())
299
259
  name String
@@ -359,6 +319,10 @@ model WorkflowStepRun {
359
319
  workflowStep WorkflowStep @relation(fields: [workflowStepId], references: [id])
360
320
  }
361
321
 
322
+ /// ─────────────────────────────────────────────
323
+ /// COMMUNICATION / CHAT / EMAIL
324
+ /// ─────────────────────────────────────────────
325
+
362
326
  model Notification {
363
327
  id String @id @default(uuid())
364
328
  userId String?
@@ -372,20 +336,61 @@ model Notification {
372
336
  user User? @relation(fields: [userId], references: [id])
373
337
  }
374
338
 
375
- model Onboarding {
376
- id String @id @default(uuid())
377
- userId String @unique
378
- persona String?
379
- setupType String?
380
- progress Json?
381
- completed Boolean @default(false)
339
+ model ChatSession {
340
+ id String @id @default(uuid())
341
+ title String?
342
+ userId String?
343
+ workspaceId String?
344
+ aiAgentId String?
345
+ status String @default("active")
346
+ metadata Json?
347
+ deletedAt DateTime?
348
+
349
+ user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
350
+ workspace Workspace? @relation(fields: [workspaceId], references: [id])
351
+ aiAgent AIAgent? @relation(fields: [aiAgentId], references: [id])
352
+ messages ChatMessage[]
382
353
 
383
354
  createdAt DateTime @default(now())
384
355
  updatedAt DateTime @updatedAt
385
356
 
386
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
357
+ @@index([userId, createdAt])
358
+ @@index([workspaceId, createdAt])
359
+ @@index([status])
360
+ }
361
+
362
+ model ChatMessage {
363
+ id String @id @default(uuid())
364
+ chatSessionId String
365
+ sender MessageRole
366
+ content String
367
+ style String?
368
+ tokensUsed Int?
369
+ metadata Json?
370
+ deletedAt DateTime?
371
+
372
+ chatSession ChatSession @relation(fields: [chatSessionId], references: [id])
373
+
374
+ createdAt DateTime @default(now())
375
+
376
+ @@index([chatSessionId, createdAt])
377
+ }
378
+
379
+ model EmailLog {
380
+ id String @id @default(uuid())
381
+ to String
382
+ subject String
383
+ type String // verification, marketing, notification, etc.
384
+ status String @default("sent")
385
+ metadata Json?
386
+ sentAt DateTime @default(now())
387
+ error String?
387
388
  }
388
389
 
390
+ /// ─────────────────────────────────────────────
391
+ /// WORKFLOW TEMPLATES & ONBOARDING PERSONAS
392
+ /// ─────────────────────────────────────────────
393
+
389
394
  model WorkflowTemplate {
390
395
  id String @id @default(uuid())
391
396
  name String
@@ -426,42 +431,133 @@ model OnboardingPersona {
426
431
  updatedAt DateTime @updatedAt
427
432
  }
428
433
 
429
- model ChatSession {
434
+ /// ─────────────────────────────────────────────
435
+ /// MONITORING / ADMIN / SYSTEM CONFIG
436
+ /// ─────────────────────────────────────────────
437
+
438
+ model Service {
430
439
  id String @id @default(uuid())
431
- title String?
432
- userId String?
433
- workspaceId String?
434
- aiAgentId String?
435
- status String @default("active")
440
+ name String
441
+ description String?
442
+ endpoint String
443
+ status String @default("healthy")
444
+ lastPing DateTime?
445
+ uptime Float?
446
+ region String?
436
447
  metadata Json?
437
- deletedAt DateTime?
448
+ createdAt DateTime @default(now())
449
+ updatedAt DateTime @updatedAt
438
450
 
439
- user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
440
- workspace Workspace? @relation(fields: [workspaceId], references: [id])
441
- aiAgent AIAgent? @relation(fields: [aiAgentId], references: [id])
442
- messages ChatMessage[]
451
+ logs ServiceLog[]
452
+ errors ErrorLog[]
453
+ }
443
454
 
455
+ model ServiceLog {
456
+ id String @id @default(uuid())
457
+ serviceId String
458
+ level String
459
+ message String
460
+ metadata Json?
444
461
  createdAt DateTime @default(now())
462
+
463
+ service Service @relation(fields: [serviceId], references: [id])
464
+ }
465
+
466
+ model ErrorLog {
467
+ id String @id @default(uuid())
468
+ serviceId String?
469
+ errorType String?
470
+ message String
471
+ stackTrace String?
472
+ context Json?
473
+ createdAt DateTime @default(now())
474
+
475
+ service Service? @relation(fields: [serviceId], references: [id])
476
+ }
477
+
478
+ model SystemConfig {
479
+ id String @id @default(uuid())
480
+ key String @unique
481
+ value Json
482
+ category String?
445
483
  updatedAt DateTime @updatedAt
484
+ }
485
+
486
+ model AuditLog {
487
+ id String @id @default(uuid())
488
+ userId String?
489
+ actorRole Role?
490
+ eventType String
491
+ targetType String?
492
+ targetId String?
493
+ description String?
494
+ metadata Json?
495
+ createdAt DateTime @default(now())
496
+
497
+ user User? @relation(fields: [userId], references: [id])
446
498
 
447
499
  @@index([userId, createdAt])
448
- @@index([workspaceId, createdAt])
449
- @@index([status])
450
500
  }
451
501
 
452
- model ChatMessage {
453
- id String @id @default(uuid())
454
- chatSessionId String
455
- sender MessageRole
456
- content String
457
- style String?
458
- tokensUsed Int?
459
- metadata Json?
460
- deletedAt DateTime?
502
+ /// ─────────────────────────────────────────────
503
+ /// BILLING / WAITLIST / JOBS / ONBOARDING
504
+ /// ─────────────────────────────────────────────
461
505
 
462
- chatSession ChatSession @relation(fields: [chatSessionId], references: [id])
506
+ model Subscription {
507
+ id String @id @default(uuid())
508
+ userId String
509
+ plan Plan
510
+ status String
511
+ startedAt DateTime
512
+ endedAt DateTime?
513
+ nextPayment DateTime?
514
+ metadata Json?
515
+
516
+ user User @relation(fields: [userId], references: [id])
517
+ }
518
+
519
+ model WaitList {
520
+ id String @id @default(uuid())
521
+ email String @unique
522
+ name String?
523
+ company String?
524
+ role String?
525
+ teamSize String?
526
+ useCase String?
527
+ consentToUpdates Boolean
528
+ referralCode String? @unique
529
+ referredBy String?
463
530
 
464
531
  createdAt DateTime @default(now())
532
+ updatedAt DateTime @updatedAt
533
+ }
465
534
 
466
- @@index([chatSessionId, createdAt])
535
+ model Job {
536
+ id String @id @default(uuid())
537
+ type String
538
+ status String @default("pending")
539
+ payload Json
540
+ retries Int @default(0)
541
+ maxRetries Int @default(3)
542
+ error String?
543
+ scheduledAt DateTime?
544
+ startedAt DateTime?
545
+ finishedAt DateTime?
546
+
547
+ createdAt DateTime @default(now())
548
+ updatedAt DateTime @updatedAt
549
+ }
550
+
551
+ model Onboarding {
552
+ id String @id @default(uuid())
553
+ userId String @unique
554
+ persona String?
555
+ setupType String?
556
+ progress Json?
557
+ completed Boolean @default(false)
558
+
559
+ createdAt DateTime @default(now())
560
+ updatedAt DateTime @updatedAt
561
+
562
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
467
563
  }