@varaos/db 1.1.2 → 1.1.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varaos/db",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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;
@@ -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,18 @@ enum Role {
18
21
  admin
19
22
  }
20
23
 
21
- /// Common status values for most resources
22
24
  enum Status {
23
25
  active
24
26
  suspended
25
27
  deleted
26
28
  }
27
29
 
28
- /// Billing plans
29
30
  enum Plan {
30
31
  free
31
32
  pro
32
33
  enterprise
33
34
  }
34
35
 
35
- /// Chat message authors
36
36
  enum MessageRole {
37
37
  user
38
38
  assistant
@@ -41,31 +41,12 @@ enum MessageRole {
41
41
  moderator
42
42
  }
43
43
 
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
- }
44
+ /// ─────────────────────────────────────────────
45
+ /// USERS & AUTH
46
+ /// ─────────────────────────────────────────────
65
47
 
66
48
  model User {
67
- id String @id @default(uuid())
68
-
49
+ id String @id @default(uuid())
69
50
  name String
70
51
  image String?
71
52
  email String @unique
@@ -145,6 +126,32 @@ model PasswordResetToken {
145
126
  @@unique([email, token])
146
127
  }
147
128
 
129
+ /// ─────────────────────────────────────────────
130
+ /// WORKSPACES & INTEGRATIONS
131
+ /// ─────────────────────────────────────────────
132
+
133
+ model Workspace {
134
+ id String @id @default(uuid())
135
+ name String
136
+ description String?
137
+ ownerId String @unique
138
+ status Status @default(active)
139
+ deletedAt DateTime?
140
+
141
+ createdAt DateTime @default(now())
142
+ updatedAt DateTime @updatedAt
143
+
144
+ owner User @relation("UserWorkspaces", fields: [ownerId], references: [id])
145
+ defaultFor User? @relation("UserDefaultWorkspace")
146
+
147
+ integrations Integration[]
148
+ aiAgents AIAgent[]
149
+ Workflow Workflow[]
150
+ ChatSession ChatSession[]
151
+
152
+ @@index([status])
153
+ }
154
+
148
155
  model Integration {
149
156
  id String @id @default(cuid())
150
157
  userId String
@@ -208,6 +215,10 @@ model IntegrationSyncLog {
208
215
  integration Integration @relation(fields: [integrationId], references: [id])
209
216
  }
210
217
 
218
+ /// ─────────────────────────────────────────────
219
+ /// AUTOMATIONS / AI / WORKFLOWS
220
+ /// ─────────────────────────────────────────────
221
+
211
222
  model AIAgent {
212
223
  id String @id @default(uuid())
213
224
  name String
@@ -238,62 +249,6 @@ model TokenTransaction {
238
249
  agent AIAgent? @relation(fields: [agentId], references: [id])
239
250
  }
240
251
 
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
252
  model Workflow {
298
253
  id String @id @default(uuid())
299
254
  name String
@@ -359,6 +314,10 @@ model WorkflowStepRun {
359
314
  workflowStep WorkflowStep @relation(fields: [workflowStepId], references: [id])
360
315
  }
361
316
 
317
+ /// ─────────────────────────────────────────────
318
+ /// COMMUNICATION / CHAT / EMAIL
319
+ /// ─────────────────────────────────────────────
320
+
362
321
  model Notification {
363
322
  id String @id @default(uuid())
364
323
  userId String?
@@ -372,20 +331,61 @@ model Notification {
372
331
  user User? @relation(fields: [userId], references: [id])
373
332
  }
374
333
 
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)
334
+ model ChatSession {
335
+ id String @id @default(uuid())
336
+ title String?
337
+ userId String?
338
+ workspaceId String?
339
+ aiAgentId String?
340
+ status String @default("active")
341
+ metadata Json?
342
+ deletedAt DateTime?
343
+
344
+ user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
345
+ workspace Workspace? @relation(fields: [workspaceId], references: [id])
346
+ aiAgent AIAgent? @relation(fields: [aiAgentId], references: [id])
347
+ messages ChatMessage[]
382
348
 
383
349
  createdAt DateTime @default(now())
384
350
  updatedAt DateTime @updatedAt
385
351
 
386
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
352
+ @@index([userId, createdAt])
353
+ @@index([workspaceId, createdAt])
354
+ @@index([status])
355
+ }
356
+
357
+ model ChatMessage {
358
+ id String @id @default(uuid())
359
+ chatSessionId String
360
+ sender MessageRole
361
+ content String
362
+ style String?
363
+ tokensUsed Int?
364
+ metadata Json?
365
+ deletedAt DateTime?
366
+
367
+ chatSession ChatSession @relation(fields: [chatSessionId], references: [id])
368
+
369
+ createdAt DateTime @default(now())
370
+
371
+ @@index([chatSessionId, createdAt])
387
372
  }
388
373
 
374
+ model EmailLog {
375
+ id String @id @default(uuid())
376
+ to String
377
+ subject String
378
+ type String // verification, marketing, notification, etc.
379
+ status String @default("sent")
380
+ metadata Json?
381
+ sentAt DateTime @default(now())
382
+ error String?
383
+ }
384
+
385
+ /// ─────────────────────────────────────────────
386
+ /// WORKFLOW TEMPLATES & ONBOARDING PERSONAS
387
+ /// ─────────────────────────────────────────────
388
+
389
389
  model WorkflowTemplate {
390
390
  id String @id @default(uuid())
391
391
  name String
@@ -426,42 +426,131 @@ model OnboardingPersona {
426
426
  updatedAt DateTime @updatedAt
427
427
  }
428
428
 
429
- model ChatSession {
429
+ /// ─────────────────────────────────────────────
430
+ /// MONITORING / ADMIN / SYSTEM CONFIG
431
+ /// ─────────────────────────────────────────────
432
+
433
+ model Service {
430
434
  id String @id @default(uuid())
431
- title String?
432
- userId String?
433
- workspaceId String?
434
- aiAgentId String?
435
- status String @default("active")
435
+ name String
436
+ description String?
437
+ endpoint String
438
+ status String @default("healthy")
439
+ lastPing DateTime?
440
+ uptime Float?
441
+ region String?
436
442
  metadata Json?
437
- deletedAt DateTime?
443
+ createdAt DateTime @default(now())
444
+ updatedAt DateTime @updatedAt
438
445
 
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[]
446
+ logs ServiceLog[]
447
+ errors ErrorLog[]
448
+ }
443
449
 
450
+ model ServiceLog {
451
+ id String @id @default(uuid())
452
+ serviceId String
453
+ level String
454
+ message String
455
+ metadata Json?
444
456
  createdAt DateTime @default(now())
457
+
458
+ service Service @relation(fields: [serviceId], references: [id])
459
+ }
460
+
461
+ model ErrorLog {
462
+ id String @id @default(uuid())
463
+ serviceId String?
464
+ errorType String?
465
+ message String
466
+ stackTrace String?
467
+ context Json?
468
+ createdAt DateTime @default(now())
469
+
470
+ service Service? @relation(fields: [serviceId], references: [id])
471
+ }
472
+
473
+ model SystemConfig {
474
+ id String @id @default(uuid())
475
+ key String @unique
476
+ value Json
477
+ category String?
445
478
  updatedAt DateTime @updatedAt
479
+ }
446
480
 
447
- @@index([userId, createdAt])
448
- @@index([workspaceId, createdAt])
449
- @@index([status])
481
+ model AuditLog {
482
+ id String @id @default(uuid())
483
+ userId String?
484
+ actorRole Role?
485
+ eventType String
486
+ targetType String?
487
+ targetId String?
488
+ description String?
489
+ metadata Json?
490
+ createdAt DateTime @default(now())
491
+
492
+ user User? @relation(fields: [userId], references: [id])
450
493
  }
451
494
 
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?
495
+ /// ─────────────────────────────────────────────
496
+ /// BILLING / WAITLIST / JOBS / ONBOARDING
497
+ /// ─────────────────────────────────────────────
461
498
 
462
- chatSession ChatSession @relation(fields: [chatSessionId], references: [id])
499
+ model Subscription {
500
+ id String @id @default(uuid())
501
+ userId String
502
+ plan Plan
503
+ status String
504
+ startedAt DateTime
505
+ endedAt DateTime?
506
+ nextPayment DateTime?
507
+ metadata Json?
508
+
509
+ user User @relation(fields: [userId], references: [id])
510
+ }
511
+
512
+ model WaitList {
513
+ id String @id @default(uuid())
514
+ email String @unique
515
+ name String?
516
+ company String?
517
+ role String?
518
+ teamSize String?
519
+ useCase String?
520
+ consentToUpdates Boolean
521
+ referralCode String? @unique
522
+ referredBy String?
463
523
 
464
524
  createdAt DateTime @default(now())
525
+ updatedAt DateTime @updatedAt
526
+ }
465
527
 
466
- @@index([chatSessionId, createdAt])
528
+ model Job {
529
+ id String @id @default(uuid())
530
+ type String
531
+ status String @default("pending")
532
+ payload Json
533
+ retries Int @default(0)
534
+ maxRetries Int @default(3)
535
+ error String?
536
+ scheduledAt DateTime?
537
+ startedAt DateTime?
538
+ finishedAt DateTime?
539
+
540
+ createdAt DateTime @default(now())
541
+ updatedAt DateTime @updatedAt
542
+ }
543
+
544
+ model Onboarding {
545
+ id String @id @default(uuid())
546
+ userId String @unique
547
+ persona String?
548
+ setupType String?
549
+ progress Json?
550
+ completed Boolean @default(false)
551
+
552
+ createdAt DateTime @default(now())
553
+ updatedAt DateTime @updatedAt
554
+
555
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
467
556
  }