@danielcok17/prisma-db 1.0.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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @legal-ai/prisma-db
2
+
3
+ Shared Prisma schema, migrations, client and helpers for Legal AI applications.
4
+
5
+ ## Usage
6
+
7
+ - Install as dependency in your apps (Git URL or npm registry)
8
+ - Ensure is set in the app runtime
9
+
10
+ ### Scripts
11
+ - (dev migrations)
12
+ - (deploy migrations)
13
+ - (prototype)
14
+ - (generate client)
15
+ - (seed data)
16
+ - (Prisma Studio)
17
+
18
+ ### Import
19
+
20
+
21
+ ### Env
22
+ Create with:
23
+
@@ -0,0 +1,4 @@
1
+ export { PrismaClient } from '@prisma/client';
2
+ export type * from '@prisma/client';
3
+ export * from './utils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,mBAAmB,gBAAgB,CAAC;AACpC,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.PrismaClient = void 0;
18
+ var client_1 = require("@prisma/client");
19
+ Object.defineProperty(exports, "PrismaClient", { enumerable: true, get: function () { return client_1.PrismaClient; } });
20
+ __exportStar(require("./utils"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yCAA8C;AAArC,sGAAA,YAAY,OAAA;AAErB,0CAAwB"}
@@ -0,0 +1,3 @@
1
+ import { PrismaClient } from '@prisma/client';
2
+ export declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs>;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,eAAO,MAAM,MAAM,gIAA+C,CAAC"}
package/dist/utils.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prisma = void 0;
4
+ const client_1 = require("@prisma/client");
5
+ const globalForPrisma = globalThis;
6
+ exports.prisma = globalForPrisma.prisma ?? new client_1.PrismaClient();
7
+ if (process.env.NODE_ENV !== 'production') {
8
+ globalForPrisma.prisma = exports.prisma;
9
+ }
10
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2CAA8C;AAE9C,MAAM,eAAe,GAAG,UAA6D,CAAC;AAEzE,QAAA,MAAM,GAAG,eAAe,CAAC,MAAM,IAAI,IAAI,qBAAY,EAAE,CAAC;AAEnE,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;IAC1C,eAAe,CAAC,MAAM,GAAG,cAAM,CAAC;AAClC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@danielcok17/prisma-db",
3
+ "version": "1.0.0",
4
+ "description": "Shared Prisma schema for Legal AI applications",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "prisma"
10
+ ],
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "scripts": {
15
+ "build": "npm run db:generate && tsc",
16
+ "dev": "tsc --watch",
17
+ "db:generate": "prisma generate --schema ./prisma/schema.prisma",
18
+ "db:push": "prisma db push --schema ./prisma/schema.prisma",
19
+ "db:migrate": "prisma migrate dev --schema ./prisma/schema.prisma",
20
+ "db:migrate:prod": "prisma migrate deploy --schema ./prisma/schema.prisma",
21
+ "db:studio": "prisma studio --schema ./prisma/schema.prisma",
22
+ "db:seed": "tsx prisma/seed.ts",
23
+ "postinstall": "prisma generate --schema ./prisma/schema.prisma"
24
+ },
25
+ "keywords": [
26
+ "prisma",
27
+ "postgres",
28
+ "schema",
29
+ "migrations"
30
+ ],
31
+ "author": "",
32
+ "license": "MIT",
33
+ "engines": {
34
+ "node": ">=18.18"
35
+ },
36
+ "dependencies": {
37
+ "@prisma/client": "^6.14.0",
38
+ "prisma": "^6.14.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^24.3.0",
42
+ "tsx": "^4.0.0",
43
+ "typescript": "^5.0.0"
44
+ }
45
+ }
@@ -0,0 +1,283 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ url = env("POSTGRES_PRISMA_URL")
8
+ directUrl = env("POSTGRES_URL_NON_POOLING")
9
+ }
10
+
11
+ model Account {
12
+ id String @id @default(cuid())
13
+ userId String
14
+ type String
15
+ provider String
16
+ providerAccountId String
17
+ refresh_token String?
18
+ access_token String?
19
+ expires_at Int?
20
+ token_type String?
21
+ scope String?
22
+ id_token String?
23
+ session_state String?
24
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
25
+
26
+ @@unique([provider, providerAccountId])
27
+ }
28
+
29
+ model User {
30
+ id String @id @default(cuid())
31
+ name String?
32
+ email String? @unique
33
+ emailVerified DateTime?
34
+ image String?
35
+ createdAt DateTime @default(now())
36
+ messageCount Int @default(100)
37
+ agreedToTerms Boolean @default(false)
38
+ practiceArea String[]
39
+ lawFirm String?
40
+ yearsOfExperience Int?
41
+ // Nové polia pre schvalovanie používateľov
42
+ isApproved Boolean @default(false) // Či je používateľ schválený
43
+ isRejected Boolean @default(false) // Či je používateľ zamietnutý
44
+ approvedAt DateTime? // Kedy bol schválený
45
+ rejectedAt DateTime? // Kedy bol zamietnutý
46
+ approvedBy String? // ID admina, ktorý schválil
47
+ rejectedBy String? // ID admina, ktorý zamietol
48
+ rejectionReason String? // Dôvod zamietnutia
49
+ // Nové polia pre tracking a žiadosť
50
+ referralSource String? // Odkiaľ sa o nás dozvedel (Google, Facebook, LinkedIn, etc.)
51
+ applicationText String? // Text žiadosti o prihlásenie
52
+ approvalRequest UserApprovalRequest?
53
+ accounts Account[]
54
+ answers Answer[]
55
+ conversations Conversation[]
56
+ feedbacks Feedback[]
57
+ pageViews PageView[]
58
+ sessions Session[]
59
+ }
60
+
61
+ // Nový model pre žiadosti o schválenie
62
+ model UserApprovalRequest {
63
+ id String @id @default(cuid())
64
+ userId String @unique
65
+ status ApprovalStatus @default(PENDING)
66
+ submittedAt DateTime @default(now())
67
+ reviewedAt DateTime?
68
+ reviewedBy String? // ID admina, ktorý preskúmal žiadosť
69
+ notes String? // Poznámky admina
70
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
71
+
72
+ @@index([status])
73
+ @@index([submittedAt])
74
+ @@index([reviewedAt])
75
+ }
76
+
77
+ // ZJEDNODUŠENÝ Conversation - len metadata, bez duplikátov
78
+ model Conversation {
79
+ id String @id @default(cuid())
80
+ name String
81
+ userId String
82
+ isShareable Boolean @default(false)
83
+ shareUrl String? @unique
84
+ sharedAt DateTime?
85
+ createdAt DateTime @default(now())
86
+ updatedAt DateTime @updatedAt
87
+ // Relácie
88
+ answers Answer[]
89
+ user User @relation(fields: [userId], references: [id])
90
+
91
+ @@index([userId])
92
+ @@index([createdAt])
93
+ }
94
+
95
+ // Hlavný model - všetky správy, bez duplikátov
96
+ model Answer {
97
+ id String @id @default(cuid())
98
+ conversationId String
99
+ messageId String @unique
100
+ role Role
101
+ content String
102
+ question String?
103
+ answer String?
104
+ evaluation String?
105
+ isWelcome Boolean @default(false)
106
+ processingTime Int?
107
+ model String?
108
+ userId String?
109
+ createdAt DateTime @default(now())
110
+ updatedAt DateTime @updatedAt
111
+ // Relácie
112
+ conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
113
+ user User? @relation(fields: [userId], references: [id])
114
+ feedback Feedback?
115
+ references Reference[]
116
+ metrics AnswerMetrics?
117
+
118
+ @@index([conversationId])
119
+ @@index([messageId])
120
+ @@index([role])
121
+ @@index([userId])
122
+ @@index([createdAt])
123
+ }
124
+
125
+ // Nová tabuľka pre metriky odpovedí
126
+ model AnswerMetrics {
127
+ id String @id @default(cuid())
128
+ answerId String @unique
129
+ // Náklady
130
+ apiCost Float? // Celkové náklady (ai_cost + rag_cost)
131
+ aiCost Float? // Náklady len na AI provider volania
132
+ ragCost Float? // Náklady na RAG operácie
133
+ // Volania
134
+ apiCalls Int? // Celkový počet volaní
135
+ aiCalls Int? // Počet AI provider volaní
136
+ ragCalls Int? // Počet RAG operácií
137
+ // Čas a výkon
138
+ apiDuration Int? // Doba spracovania v ms
139
+ // AI Provider a Model
140
+ aiProvider String? // Hlavný AI provider
141
+ aiModel String? // Hlavný AI model
142
+ aiProvidersUsed String[] // Všetky použité AI providery
143
+ aiModelsUsed String[] // Všetky použité AI modely
144
+ // Timestamps
145
+ createdAt DateTime @default(now())
146
+ updatedAt DateTime @updatedAt
147
+ // Relations
148
+ answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
149
+
150
+ @@index([answerId])
151
+ @@index([apiCost])
152
+ @@index([apiDuration])
153
+ @@index([aiProvider])
154
+ @@index([createdAt])
155
+ }
156
+
157
+ model Feedback {
158
+ id String @id @default(cuid())
159
+ answerId String @unique
160
+ rating FeedbackRating
161
+ feedbackTypes String[]
162
+ customFeedback String?
163
+ userId String
164
+ messageContent String?
165
+ createdAt DateTime @default(now())
166
+ answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
167
+ user User @relation(fields: [userId], references: [id])
168
+
169
+ @@index([rating])
170
+ @@index([userId])
171
+ @@index([answerId])
172
+ }
173
+
174
+ // ZJEDNODUŠENÝ Reference - len na Answer, bez duplikátov
175
+ model Reference {
176
+ id String @id @default(cuid())
177
+ answerId String // Len answerId - konzistentné
178
+ type ReferenceType
179
+ title String
180
+ reference String
181
+ summary String?
182
+ url String?
183
+ uuid String?
184
+ relevance Float?
185
+ citationNumber Int?
186
+ metadata Json?
187
+ userId String?
188
+ createdAt DateTime @default(now())
189
+ // Relácie
190
+ answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
191
+
192
+ @@index([answerId])
193
+ @@index([type])
194
+ @@index([reference])
195
+ @@index([userId])
196
+ @@index([createdAt])
197
+ }
198
+
199
+ model PageView {
200
+ id String @id @default(cuid())
201
+ userId String?
202
+ sessionId String
203
+ page String
204
+ path String
205
+ referrer String?
206
+ userAgent String?
207
+ ipAddress String?
208
+ country String?
209
+ city String?
210
+ deviceType String?
211
+ browser String?
212
+ os String?
213
+ screenSize String?
214
+ language String?
215
+ timeOnPage Int?
216
+ isBounce Boolean @default(true)
217
+ createdAt DateTime @default(now())
218
+ session Session @relation(fields: [sessionId], references: [sessionId], onDelete: SetNull)
219
+ user User? @relation(fields: [userId], references: [id])
220
+
221
+ @@index([userId])
222
+ @@index([sessionId])
223
+ @@index([page])
224
+ @@index([createdAt])
225
+ @@index([country])
226
+ @@index([deviceType])
227
+ }
228
+
229
+ model Session {
230
+ id String @id @default(cuid())
231
+ sessionId String @unique
232
+ userId String?
233
+ startedAt DateTime @default(now())
234
+ endedAt DateTime?
235
+ duration Int?
236
+ pageViews PageView[]
237
+ user User? @relation(fields: [userId], references: [id])
238
+
239
+ @@index([sessionId])
240
+ @@index([userId])
241
+ @@index([startedAt])
242
+ }
243
+
244
+ enum Role {
245
+ USER
246
+ ASSISTANT
247
+ SYSTEM
248
+ }
249
+
250
+ enum FeedbackRating {
251
+ LIKE
252
+ DISLIKE
253
+ NEUTRAL
254
+ }
255
+
256
+ enum ReferenceType {
257
+ LAW
258
+ CASE
259
+ REGULATION
260
+ DOCUMENT
261
+ OTHER
262
+ }
263
+
264
+ enum ApprovalStatus {
265
+ PENDING
266
+ APPROVED
267
+ REJECTED
268
+ }
269
+
270
+ // Nový model pre logovanie admin akcií
271
+ model AdminActionLog {
272
+ id String @id @default(cuid())
273
+ action String // APPROVE_USER, REJECT_USER, etc.
274
+ targetUserId String // ID používateľa, na ktorého sa akcia vzťahuje
275
+ adminEmail String // E-mail admina, ktorý vykonal akciu
276
+ details Json? // Ďalšie detaily akcie (reason, notes, etc.)
277
+ createdAt DateTime @default(now())
278
+
279
+ @@index([action])
280
+ @@index([targetUserId])
281
+ @@index([adminEmail])
282
+ @@index([createdAt])
283
+ }
package/prisma/seed.ts ADDED
File without changes