@varaos/db 1.4.4 → 1.4.6
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
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "AdminSession" (
|
|
3
|
+
"id" TEXT NOT NULL,
|
|
4
|
+
"userId" TEXT NOT NULL,
|
|
5
|
+
"token" TEXT NOT NULL,
|
|
6
|
+
"role" "Role" NOT NULL,
|
|
7
|
+
"ip" TEXT,
|
|
8
|
+
"userAgent" TEXT,
|
|
9
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
10
|
+
"revokedAt" TIMESTAMP(3),
|
|
11
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
12
|
+
|
|
13
|
+
CONSTRAINT "AdminSession_pkey" PRIMARY KEY ("id")
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
-- CreateTable
|
|
17
|
+
CREATE TABLE "AdminOTP" (
|
|
18
|
+
"id" TEXT NOT NULL,
|
|
19
|
+
"userId" TEXT NOT NULL,
|
|
20
|
+
"code" TEXT NOT NULL,
|
|
21
|
+
"used" BOOLEAN NOT NULL DEFAULT false,
|
|
22
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
23
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
+
|
|
25
|
+
CONSTRAINT "AdminOTP_pkey" PRIMARY KEY ("id")
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- CreateTable
|
|
29
|
+
CREATE TABLE "ImpersonationSession" (
|
|
30
|
+
"id" TEXT NOT NULL,
|
|
31
|
+
"actorId" TEXT NOT NULL,
|
|
32
|
+
"targetId" TEXT NOT NULL,
|
|
33
|
+
"token" TEXT NOT NULL,
|
|
34
|
+
"reason" TEXT NOT NULL,
|
|
35
|
+
"used" BOOLEAN NOT NULL DEFAULT false,
|
|
36
|
+
"usedAt" TIMESTAMP(3),
|
|
37
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
38
|
+
"revokedAt" TIMESTAMP(3),
|
|
39
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
40
|
+
|
|
41
|
+
CONSTRAINT "ImpersonationSession_pkey" PRIMARY KEY ("id")
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
-- CreateIndex
|
|
45
|
+
CREATE UNIQUE INDEX "AdminSession_token_key" ON "AdminSession"("token");
|
|
46
|
+
|
|
47
|
+
-- CreateIndex
|
|
48
|
+
CREATE INDEX "AdminSession_userId_idx" ON "AdminSession"("userId");
|
|
49
|
+
|
|
50
|
+
-- CreateIndex
|
|
51
|
+
CREATE INDEX "AdminSession_token_idx" ON "AdminSession"("token");
|
|
52
|
+
|
|
53
|
+
-- CreateIndex
|
|
54
|
+
CREATE INDEX "AdminOTP_userId_used_idx" ON "AdminOTP"("userId", "used");
|
|
55
|
+
|
|
56
|
+
-- CreateIndex
|
|
57
|
+
CREATE UNIQUE INDEX "ImpersonationSession_token_key" ON "ImpersonationSession"("token");
|
|
58
|
+
|
|
59
|
+
-- CreateIndex
|
|
60
|
+
CREATE INDEX "ImpersonationSession_actorId_idx" ON "ImpersonationSession"("actorId");
|
|
61
|
+
|
|
62
|
+
-- CreateIndex
|
|
63
|
+
CREATE INDEX "ImpersonationSession_targetId_idx" ON "ImpersonationSession"("targetId");
|
|
64
|
+
|
|
65
|
+
-- AddForeignKey
|
|
66
|
+
ALTER TABLE "AdminSession" ADD CONSTRAINT "AdminSession_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
67
|
+
|
|
68
|
+
-- AddForeignKey
|
|
69
|
+
ALTER TABLE "AdminOTP" ADD CONSTRAINT "AdminOTP_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
70
|
+
|
|
71
|
+
-- AddForeignKey
|
|
72
|
+
ALTER TABLE "ImpersonationSession" ADD CONSTRAINT "ImpersonationSession_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
73
|
+
|
|
74
|
+
-- AddForeignKey
|
|
75
|
+
ALTER TABLE "ImpersonationSession" ADD CONSTRAINT "ImpersonationSession_targetId_fkey" FOREIGN KEY ("targetId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
package/prisma/schema.prisma
CHANGED
|
@@ -369,6 +369,12 @@ model User {
|
|
|
369
369
|
|
|
370
370
|
toolRequests ToolRequest[]
|
|
371
371
|
|
|
372
|
+
/// Admin panel relations
|
|
373
|
+
adminSessions AdminSession[]
|
|
374
|
+
adminOTPs AdminOTP[]
|
|
375
|
+
impersonationsAsActor ImpersonationSession[] @relation("ImpersonationActor")
|
|
376
|
+
impersonationsAsTarget ImpersonationSession[] @relation("ImpersonationTarget")
|
|
377
|
+
|
|
372
378
|
@@index([status])
|
|
373
379
|
}
|
|
374
380
|
|
|
@@ -2049,3 +2055,57 @@ model DeadLetterJob {
|
|
|
2049
2055
|
@@index([reviewed])
|
|
2050
2056
|
@@index([createdAt])
|
|
2051
2057
|
}
|
|
2058
|
+
|
|
2059
|
+
|
|
2060
|
+
/// ─────────────────────────────────────────────────────────────
|
|
2061
|
+
/// ADMIN USER MANAGEMENT (For SaaS Admin Panel)
|
|
2062
|
+
/// ─────────────────────────────────────────────────────────────
|
|
2063
|
+
|
|
2064
|
+
model AdminSession {
|
|
2065
|
+
id String @id @default(uuid())
|
|
2066
|
+
userId String
|
|
2067
|
+
token String @unique
|
|
2068
|
+
role Role
|
|
2069
|
+
ip String?
|
|
2070
|
+
userAgent String?
|
|
2071
|
+
expiresAt DateTime
|
|
2072
|
+
revokedAt DateTime?
|
|
2073
|
+
createdAt DateTime @default(now())
|
|
2074
|
+
|
|
2075
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
2076
|
+
|
|
2077
|
+
@@index([userId])
|
|
2078
|
+
@@index([token])
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
model AdminOTP {
|
|
2082
|
+
id String @id @default(uuid())
|
|
2083
|
+
userId String
|
|
2084
|
+
code String
|
|
2085
|
+
used Boolean @default(false)
|
|
2086
|
+
expiresAt DateTime
|
|
2087
|
+
createdAt DateTime @default(now())
|
|
2088
|
+
|
|
2089
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
2090
|
+
|
|
2091
|
+
@@index([userId, used])
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
model ImpersonationSession {
|
|
2095
|
+
id String @id @default(uuid())
|
|
2096
|
+
actorId String
|
|
2097
|
+
targetId String
|
|
2098
|
+
token String @unique
|
|
2099
|
+
reason String
|
|
2100
|
+
used Boolean @default(false)
|
|
2101
|
+
usedAt DateTime?
|
|
2102
|
+
expiresAt DateTime
|
|
2103
|
+
revokedAt DateTime?
|
|
2104
|
+
createdAt DateTime @default(now())
|
|
2105
|
+
|
|
2106
|
+
actor User @relation("ImpersonationActor", fields: [actorId], references: [id])
|
|
2107
|
+
target User @relation("ImpersonationTarget", fields: [targetId], references: [id])
|
|
2108
|
+
|
|
2109
|
+
@@index([actorId])
|
|
2110
|
+
@@index([targetId])
|
|
2111
|
+
}
|