@varaos/db 1.1.17 → 1.1.19

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.17",
3
+ "version": "1.1.19",
4
4
  "private": false,
5
5
  "main": "index.js",
6
6
  "files": [
@@ -0,0 +1,36 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - Changed the type of `category` on the `UserFile` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
5
+
6
+ */
7
+ -- CreateEnum
8
+ CREATE TYPE "public"."FileCategory" AS ENUM ('avatar', 'media', 'attachment', 'memory', 'export');
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "public"."UserFile" DROP COLUMN "category",
12
+ ADD COLUMN "category" "public"."FileCategory" NOT NULL;
13
+
14
+ -- CreateTable
15
+ CREATE TABLE "public"."UploadIntent" (
16
+ "id" TEXT NOT NULL,
17
+ "userId" TEXT NOT NULL,
18
+ "category" "public"."FileCategory" NOT NULL,
19
+ "size" BIGINT NOT NULL,
20
+ "objectKey" TEXT NOT NULL,
21
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
22
+
23
+ CONSTRAINT "UploadIntent_pkey" PRIMARY KEY ("id")
24
+ );
25
+
26
+ -- CreateIndex
27
+ CREATE INDEX "UploadIntent_userId_idx" ON "public"."UploadIntent"("userId");
28
+
29
+ -- CreateIndex
30
+ CREATE INDEX "UploadIntent_userId_category_idx" ON "public"."UploadIntent"("userId", "category");
31
+
32
+ -- CreateIndex
33
+ CREATE INDEX "UserFile_category_idx" ON "public"."UserFile"("category");
34
+
35
+ -- CreateIndex
36
+ CREATE INDEX "UserFile_userId_category_idx" ON "public"."UserFile"("userId", "category");
@@ -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;
@@ -68,6 +68,20 @@ enum ReactionType {
68
68
  WOW
69
69
  }
70
70
 
71
+ enum FileCategory {
72
+ avatar
73
+ media
74
+ attachment
75
+ memory
76
+ export
77
+ }
78
+
79
+ enum TwoFactorMethod {
80
+ totp
81
+ email
82
+ webauthn
83
+ }
84
+
71
85
  /// ─────────────────────────────────────────────
72
86
  /// USERS & AUTH
73
87
  /// ─────────────────────────────────────────────
@@ -90,12 +104,14 @@ model User {
90
104
  lastLogin DateTime?
91
105
  lastPasswordChange DateTime?
92
106
  twoFactorEnabled Boolean @default(false)
93
- twoFactorSecret String?
94
- metadata Json?
95
- plan Plan @default(free)
96
- tokenBalance Int @default(0)
97
- creditsUsed Int @default(0)
98
- deletedAt DateTime?
107
+
108
+ userTwoFactor UserTwoFactor?
109
+
110
+ metadata Json?
111
+ plan Plan @default(free)
112
+ tokenBalance Int @default(0)
113
+ creditsUsed Int @default(0)
114
+ deletedAt DateTime?
99
115
 
100
116
  authType AuthType @default(oauth)
101
117
 
@@ -133,10 +149,10 @@ model UserFile {
133
149
  id String @id @default(uuid())
134
150
  userId String
135
151
 
136
- path String // local path or CDN URL
152
+ path String // Spaces object key (users/{userId}/{category}/{fileId}.ext)
137
153
  size BigInt // bytes
138
154
  mimeType String
139
- category String // avatar | memory | export | attachment
155
+ category FileCategory
140
156
 
141
157
  checksum String? // sha256 or md5 for integrity verification
142
158
  metadata Json?
@@ -147,6 +163,7 @@ model UserFile {
147
163
 
148
164
  @@index([userId])
149
165
  @@index([category])
166
+ @@index([userId, category])
150
167
  }
151
168
 
152
169
  model UserSession {
@@ -167,6 +184,18 @@ model UserSession {
167
184
  @@index([userId])
168
185
  }
169
186
 
187
+ model UploadIntent {
188
+ id String @id
189
+ userId String
190
+ category FileCategory
191
+ size BigInt
192
+ objectKey String
193
+ createdAt DateTime @default(now())
194
+
195
+ @@index([userId])
196
+ @@index([userId, category])
197
+ }
198
+
170
199
  model UserEmail {
171
200
  id String @id @default(uuid())
172
201
  userId String
@@ -179,6 +208,29 @@ model UserEmail {
179
208
  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
180
209
  }
181
210
 
211
+ model UserTwoFactor {
212
+ id String @id @default(uuid())
213
+ userId String @unique
214
+
215
+ method TwoFactorMethod @default(totp)
216
+ secret String? // null when disabled or method != totp
217
+ enabled Boolean @default(false)
218
+
219
+ lastVerifiedAt DateTime?
220
+ enabledAt DateTime?
221
+
222
+ recoveryEmailVerifiedAt DateTime?
223
+
224
+ backupCodes Json? // [{ hash, used, usedAt }]
225
+
226
+ createdAt DateTime @default(now())
227
+ updatedAt DateTime @updatedAt
228
+
229
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
230
+
231
+ @@index([userId])
232
+ }
233
+
182
234
  model Account {
183
235
  id String @id @default(uuid())
184
236
  userId String