@varaos/db 1.1.18 → 1.2.0

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.18",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,37 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `twoFactorSecret` on the `User` table. All the data in the column will be lost.
5
+
6
+ */
7
+ -- CreateEnum
8
+ CREATE TYPE "public"."TwoFactorMethod" AS ENUM ('totp', 'email', 'webauthn');
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "public"."User" DROP COLUMN "twoFactorSecret";
12
+
13
+ -- CreateTable
14
+ CREATE TABLE "public"."UserTwoFactor" (
15
+ "id" TEXT NOT NULL,
16
+ "userId" TEXT NOT NULL,
17
+ "method" "public"."TwoFactorMethod" NOT NULL DEFAULT 'totp',
18
+ "secret" TEXT,
19
+ "enabled" BOOLEAN NOT NULL DEFAULT false,
20
+ "lastVerifiedAt" TIMESTAMP(3),
21
+ "enabledAt" TIMESTAMP(3),
22
+ "recoveryEmailVerifiedAt" TIMESTAMP(3),
23
+ "backupCodes" JSONB,
24
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
25
+ "updatedAt" TIMESTAMP(3) NOT NULL,
26
+
27
+ CONSTRAINT "UserTwoFactor_pkey" PRIMARY KEY ("id")
28
+ );
29
+
30
+ -- CreateIndex
31
+ CREATE UNIQUE INDEX "UserTwoFactor_userId_key" ON "public"."UserTwoFactor"("userId");
32
+
33
+ -- CreateIndex
34
+ CREATE INDEX "UserTwoFactor_userId_idx" ON "public"."UserTwoFactor"("userId");
35
+
36
+ -- AddForeignKey
37
+ ALTER TABLE "public"."UserTwoFactor" ADD CONSTRAINT "UserTwoFactor_userId_fkey" FOREIGN KEY ("userId") REFERENCES "public"."User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,62 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - The `status` column on the `Workflow` table would be dropped and recreated. This will lead to data loss if there is data in the column.
5
+ - The `status` column on the `WorkflowRun` table would be dropped and recreated. This will lead to data loss if there is data in the column.
6
+ - The `status` column on the `WorkflowStep` table would be dropped and recreated. This will lead to data loss if there is data in the column.
7
+ - The `status` column on the `WorkflowStepRun` table would be dropped and recreated. This will lead to data loss if there is data in the column.
8
+ - Changed the type of `status` on the `Subscription` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
9
+
10
+ */
11
+ -- CreateEnum
12
+ CREATE TYPE "public"."SubscriptionStatus" AS ENUM ('active', 'trialing', 'past_due', 'canceled', 'paused');
13
+
14
+ -- CreateEnum
15
+ CREATE TYPE "public"."WorkflowStatus" AS ENUM ('active', 'paused', 'archived');
16
+
17
+ -- CreateEnum
18
+ CREATE TYPE "public"."WorkflowRunStatus" AS ENUM ('running', 'completed', 'failed', 'canceled');
19
+
20
+ -- CreateEnum
21
+ CREATE TYPE "public"."WorkflowStepStatus" AS ENUM ('active', 'paused', 'deprecated');
22
+
23
+ -- CreateEnum
24
+ CREATE TYPE "public"."WorkflowStepRunStatus" AS ENUM ('pending', 'running', 'completed', 'failed', 'skipped');
25
+
26
+ -- DropIndex
27
+ DROP INDEX "public"."UserSession_userId_idx";
28
+
29
+ -- AlterTable
30
+ ALTER TABLE "public"."BillingEvent" ADD COLUMN "error" TEXT,
31
+ ADD COLUMN "processedAt" TIMESTAMP(3);
32
+
33
+ -- AlterTable
34
+ ALTER TABLE "public"."Subscription" ADD COLUMN "currentPeriodEnd" TIMESTAMP(3),
35
+ ADD COLUMN "currentPeriodStart" TIMESTAMP(3),
36
+ DROP COLUMN "status",
37
+ ADD COLUMN "status" "public"."SubscriptionStatus" NOT NULL;
38
+
39
+ -- AlterTable
40
+ ALTER TABLE "public"."User" ADD COLUMN "chatCount" INTEGER NOT NULL DEFAULT 0,
41
+ ADD COLUMN "integrationCount" INTEGER NOT NULL DEFAULT 0,
42
+ ADD COLUMN "lastActiveAt" TIMESTAMP(3),
43
+ ADD COLUMN "workflowCount" INTEGER NOT NULL DEFAULT 0;
44
+
45
+ -- AlterTable
46
+ ALTER TABLE "public"."Workflow" DROP COLUMN "status",
47
+ ADD COLUMN "status" "public"."WorkflowStatus" NOT NULL DEFAULT 'active';
48
+
49
+ -- AlterTable
50
+ ALTER TABLE "public"."WorkflowRun" DROP COLUMN "status",
51
+ ADD COLUMN "status" "public"."WorkflowRunStatus" NOT NULL DEFAULT 'running';
52
+
53
+ -- AlterTable
54
+ ALTER TABLE "public"."WorkflowStep" DROP COLUMN "status",
55
+ ADD COLUMN "status" "public"."WorkflowStepStatus" NOT NULL DEFAULT 'active';
56
+
57
+ -- AlterTable
58
+ ALTER TABLE "public"."WorkflowStepRun" DROP COLUMN "status",
59
+ ADD COLUMN "status" "public"."WorkflowStepRunStatus" NOT NULL DEFAULT 'pending';
60
+
61
+ -- CreateIndex
62
+ CREATE INDEX "UserSession_userId_revoked_idx" ON "public"."UserSession"("userId", "revoked");
@@ -76,6 +76,49 @@ enum FileCategory {
76
76
  export
77
77
  }
78
78
 
79
+ enum TwoFactorMethod {
80
+ totp
81
+ email
82
+ webauthn
83
+ }
84
+
85
+ enum SubscriptionStatus {
86
+ active
87
+ trialing
88
+ past_due
89
+ canceled
90
+ paused
91
+ }
92
+
93
+ enum WorkflowStatus {
94
+ active
95
+ paused
96
+ archived
97
+ }
98
+
99
+ enum WorkflowRunStatus {
100
+ running
101
+ completed
102
+ failed
103
+ canceled
104
+ }
105
+
106
+ enum WorkflowStepStatus {
107
+ active
108
+ paused
109
+ deprecated
110
+ }
111
+
112
+ enum WorkflowStepRunStatus {
113
+ pending
114
+ running
115
+ completed
116
+ failed
117
+ skipped
118
+ }
119
+
120
+
121
+
79
122
  /// ─────────────────────────────────────────────
80
123
  /// USERS & AUTH
81
124
  /// ─────────────────────────────────────────────
@@ -98,12 +141,20 @@ model User {
98
141
  lastLogin DateTime?
99
142
  lastPasswordChange DateTime?
100
143
  twoFactorEnabled Boolean @default(false)
101
- twoFactorSecret String?
102
- metadata Json?
103
- plan Plan @default(free)
104
- tokenBalance Int @default(0)
105
- creditsUsed Int @default(0)
106
- deletedAt DateTime?
144
+
145
+ userTwoFactor UserTwoFactor?
146
+
147
+ metadata Json?
148
+ deletedAt DateTime?
149
+ plan Plan @default(free)
150
+ tokenBalance Int @default(0)
151
+ creditsUsed Int @default(0)
152
+
153
+ chatCount Int @default(0)
154
+ workflowCount Int @default(0)
155
+ integrationCount Int @default(0)
156
+
157
+ lastActiveAt DateTime?
107
158
 
108
159
  authType AuthType @default(oauth)
109
160
 
@@ -173,16 +224,16 @@ model UserSession {
173
224
 
174
225
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
175
226
 
176
- @@index([userId])
227
+ @@index([userId, revoked])
177
228
  }
178
229
 
179
230
  model UploadIntent {
180
- id String @id
231
+ id String @id
181
232
  userId String
182
233
  category FileCategory
183
234
  size BigInt
184
235
  objectKey String
185
- createdAt DateTime @default(now())
236
+ createdAt DateTime @default(now())
186
237
 
187
238
  @@index([userId])
188
239
  @@index([userId, category])
@@ -200,6 +251,29 @@ model UserEmail {
200
251
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
201
252
  }
202
253
 
254
+ model UserTwoFactor {
255
+ id String @id @default(uuid())
256
+ userId String @unique
257
+
258
+ method TwoFactorMethod @default(totp)
259
+ secret String? // null when disabled or method != totp
260
+ enabled Boolean @default(false)
261
+
262
+ lastVerifiedAt DateTime?
263
+ enabledAt DateTime?
264
+
265
+ recoveryEmailVerifiedAt DateTime?
266
+
267
+ backupCodes Json? // [{ hash, used, usedAt }]
268
+
269
+ createdAt DateTime @default(now())
270
+ updatedAt DateTime @updatedAt
271
+
272
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
273
+
274
+ @@index([userId])
275
+ }
276
+
203
277
  model Account {
204
278
  id String @id @default(uuid())
205
279
  userId String
@@ -389,10 +463,10 @@ model TokenTransaction {
389
463
  }
390
464
 
391
465
  model Workflow {
392
- id String @id @default(uuid())
466
+ id String @id @default(uuid())
393
467
  name String
394
468
  description String?
395
- status String @default("active")
469
+ status WorkflowStatus @default(active)
396
470
  userId String
397
471
  workspaceId String?
398
472
 
@@ -411,7 +485,7 @@ model WorkflowStep {
411
485
  type String
412
486
  config Json
413
487
  order Int
414
- status String @default("active")
488
+ status WorkflowStepStatus @default(active)
415
489
 
416
490
  workflow Workflow @relation(fields: [workflowId], references: [id])
417
491
 
@@ -421,9 +495,9 @@ model WorkflowStep {
421
495
  }
422
496
 
423
497
  model WorkflowRun {
424
- id String @id @default(uuid())
498
+ id String @id @default(uuid())
425
499
  workflowId String
426
- status String @default("running")
500
+ status WorkflowRunStatus @default(running)
427
501
  input Json?
428
502
  output Json?
429
503
  error String?
@@ -441,7 +515,7 @@ model WorkflowStepRun {
441
515
  id String @id @default(uuid())
442
516
  workflowRunId String
443
517
  workflowStepId String
444
- status String @default("pending")
518
+ status WorkflowStepRunStatus @default(pending)
445
519
  input Json?
446
520
  output Json?
447
521
  error String?
@@ -651,12 +725,20 @@ model SecurityEvent {
651
725
  /// ─────────────────────────────────────────────
652
726
 
653
727
  model Subscription {
654
- id String @id @default(uuid())
655
- userId String
656
- plan Plan
657
- status String // active | trialing | past_due | canceled
658
- startedAt DateTime
659
- endedAt DateTime?
728
+ id String @id @default(uuid())
729
+ userId String
730
+ plan Plan
731
+ status SubscriptionStatus // active | trialing | past_due | canceled
732
+
733
+ // ── Lifecycle (rarely changes)
734
+ startedAt DateTime
735
+ endedAt DateTime?
736
+
737
+ // ── Billing cycle (changes every invoice)
738
+ currentPeriodStart DateTime?
739
+ currentPeriodEnd DateTime?
740
+
741
+ // ── Provider scheduling (informational only)
660
742
  nextPayment DateTime?
661
743
 
662
744
  razorpayCustomerId String?
@@ -696,8 +778,11 @@ model BillingEvent {
696
778
  eventType String
697
779
  eventId String @unique // razorpay event ID
698
780
 
699
- payload Json
700
- processed Boolean @default(false)
781
+ payload Json
782
+ processed Boolean @default(false)
783
+ processedAt DateTime?
784
+ error String?
785
+
701
786
  createdAt DateTime @default(now())
702
787
 
703
788
  @@index([provider, eventType])