Repository navigation
Expand file tree
/
Copy pathschema.prisma
More file actions
495 lines (447 loc) · 17.6 KB
/
Copy pathschema.prisma
File metadata and controls
495 lines (447 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum UserRole {
PLATFORM_ADMIN
ORGANIZER
ATTENDEE
}
enum OrgMemberRole {
OWNER
ADMIN
STAFF
}
/// Mirrors the 12 supported verticals. Kept as an enum on the backend (unlike
/// the contract's free-text `category`) so the dashboard/marketplace can
/// filter and render industry-specific copy without string matching.
enum Industry {
CONCERTS
FLIGHTS
SPORTS
FESTIVALS
CONFERENCES
BUS
MOVIE_THEATERS
MUSEUMS
TOURIST_ATTRACTIONS
PUBLIC_TRANSPORT
UNIVERSITIES
CORPORATE_EVENTS
}
enum EventStatus {
DRAFT
PUBLISHED
CANCELLED
}
/// Cached projection of the on-chain `TicketStatus`. The contract remains the
/// source of truth; this column exists so listing/search queries don't need
/// a Soroban RPC round trip, and is reconciled on every write path and by a
/// periodic reconciliation job.
enum TicketStatus {
VALID
USED
REVOKED
RESALE
}
/// Off-chain record of a primary-sale refund for a REVOKED ticket (#141).
/// The chain has no refund concept; this tracks the admin-driven payout.
enum RefundStatus {
PENDING
COMPLETED
}
model Refund {
id String @id @default(uuid())
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId String @unique
status RefundStatus @default(PENDING)
createdAt DateTime @default(now())
completedAt DateTime?
}
enum ResaleListingStatus {
ACTIVE
SOLD
CANCELLED
}
/// Position in a `WaitlistEntry` queue is derived from `createdAt` (FIFO), not
/// stored directly, so re-ordering never requires rewriting every row.
enum WaitlistEntryStatus {
WAITING
OFFERED
CONVERTED
EXPIRED
CANCELLED
}
enum PromoCodeDiscountType {
PERCENT
FIXED
}
model User {
id String @id @default(uuid())
email String @unique
passwordHash String
name String
role UserRole @default(ATTENDEE)
/// Stellar (G...) address used to receive tickets and settle payments.
stellarPublicKey String? @unique
memberships OrganizationMember[]
tickets Ticket[]
resaleListings ResaleListing[]
eventReminders EventReminder[]
waitlistEntries WaitlistEntry[]
promoRedemptions PromoCodeRedemption[]
auditLogs AuditLog[]
pendingTxs PendingTx[]
sentInvitations OrganizationInvitation[] @relation("InvitationInviter")
acceptedInvitations OrganizationInvitation[] @relation("InvitationAcceptor")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Organization {
id String @id @default(uuid())
name String
slug String @unique
industry Industry
/// Stellar (G...) address that signs `create_event`/`issue_ticket` calls
/// and receives primary-sale + royalty payments for this organizer.
stellarAccount String
logoUrl String?
websiteUrl String?
/// Default `Event.maxResaleMultiplierBps` applied when a new event's DTO
/// omits it.
defaultMaxResaleMultiplierBps Int @default(11000)
/// Default `Event.royaltyBps` applied when a new event's DTO omits it.
defaultRoyaltyBps Int @default(500)
members OrganizationMember[]
invitations OrganizationInvitation[]
events Event[]
webhookEndpoints WebhookEndpoint[]
/// #207 — soft-delete marker. Null = live; non-null = deleted at that time.
/// Rows are never hard-deleted by the app; queries filter `deletedAt: null`.
deletedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model OrganizationMember {
id String @id @default(uuid())
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
role OrgMemberRole @default(STAFF)
createdAt DateTime @default(now())
@@unique([organizationId, userId])
@@index([userId])
}
/// An invite for an email address to join an `Organization`, so members can be
/// added before they have an account. Only a SHA-256 hash of the opaque token
/// is stored; the raw token is returned once at creation. Accepting creates
/// the `OrganizationMember`; invites expire 7 days after creation.
model OrganizationInvitation {
id String @id @default(uuid())
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String
/// Stored trimmed and lower-cased, matching `User.email`.
email String
role OrgMemberRole @default(STAFF)
tokenHash String @unique
invitedBy User? @relation("InvitationInviter", fields: [invitedById], references: [id], onDelete: SetNull)
invitedById String?
expiresAt DateTime
acceptedAt DateTime?
acceptedBy User? @relation("InvitationAcceptor", fields: [acceptedById], references: [id], onDelete: SetNull)
acceptedById String?
createdAt DateTime @default(now())
@@index([organizationId, email])
}
model Event {
id String @id @default(uuid())
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String
name String
description String
imageUrl String?
category Industry
venue String
/// IANA time-zone identifier used to display UTC timestamps at the venue.
timezone String
startsAt DateTime
endsAt DateTime?
/// The `event_id` (u64) this event was registered under on the ticketing
/// contract via `create_event`. Null until the on-chain call succeeds.
chainEventId BigInt? @unique
/// #381 — when `chainEventId` was last reserved by a publish build. An
/// unconfirmed reservation expires with its envelope's time bound and is
/// then reused by the next publish attempt.
chainEventIdReservedAt DateTime?
publishedTxHash String?
maxResaleMultiplierBps Int @default(11000)
royaltyBps Int @default(500)
status EventStatus @default(DRAFT)
ticketTypes TicketType[]
tickets Ticket[]
reminders EventReminder[]
promoCodes PromoCode[]
gates Gate[]
scannerDevices ScannerDevice[]
/// #207 — soft-delete marker. Null = live; non-null = deleted at that time.
deletedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([organizationId])
@@index([status, startsAt])
@@index([status, category, startsAt])
}
model TicketType {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
name String
/// Face-value price in the platform's settlement token's smallest unit.
price BigInt
quantityTotal Int
quantityIssued Int @default(0)
saleStartsAt DateTime?
saleEndsAt DateTime?
isHidden Boolean @default(false)
tickets Ticket[]
waitlistEntries WaitlistEntry[]
createdAt DateTime @default(now())
@@unique([eventId, name])
@@index([eventId])
}
model Ticket {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
ticketType TicketType @relation(fields: [ticketTypeId], references: [id])
ticketTypeId String
owner User @relation(fields: [ownerId], references: [id])
ownerId String
/// The `ticket_id` (u64) returned by `issue_ticket`/`purchase_primary`.
chainTicketId BigInt @unique
seat String @default("unassigned")
status TicketStatus @default(VALID)
/// Opaque per-ticket secret embedded in the scannable QR code; verification
/// checks this against the DB *and* the on-chain owner/status before a gate
/// scan is accepted, so a photographed QR code alone can't be reused.
qrSecret String @unique @default(uuid())
issuedTxHash String?
checkedInAt DateTime?
/// Reason for check-in when scanner fails and staff override is used.
checkInReason String?
/// Which physical `Gate` this ticket was scanned at, if any. Null for
/// tickets checked in before gates existed, or checked in through a
/// non-gated flow.
checkedInGate Gate? @relation(fields: [checkedInGateId], references: [id])
checkedInGateId String?
resaleListings ResaleListing[]
promoRedemption PromoCodeRedemption?
refund Refund?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// #213 — covers GET /tickets/mine (owner + optional status filter).
@@index([ownerId, status])
@@index([eventId])
@@index([ticketTypeId])
// #211 — seat uniqueness for assigned seats is enforced by a partial
// unique index in a raw migration (see prisma/migrations/*_ticket_seat_partial_unique/migration.sql):
// CREATE UNIQUE INDEX "Ticket_eventId_seat_key" ON "Ticket"("eventId", "seat")
// WHERE "seat" <> 'unassigned'.
// Prisma cannot express partial indexes, so no @@unique here by design.
}
model ResaleListing {
id String @id @default(uuid())
ticket Ticket @relation(fields: [ticketId], references: [id], onDelete: Cascade)
ticketId String
seller User @relation(fields: [sellerId], references: [id])
sellerId String
price BigInt
status ResaleListingStatus @default(ACTIVE)
txHash String?
expiresAt DateTime?
priceHistory ResalePriceHistory[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// #214 — resale lookups filter by ticket and status.
@@index([ticketId, status])
@@index([sellerId])
// #394 — marketplace feeds filter by status and sort by creation time.
@@index([status, createdAt])
}
model ResalePriceHistory {
id String @id @default(uuid())
resaleListing ResaleListing @relation(fields: [resaleListingId], references: [id], onDelete: Cascade)
resaleListingId String
price BigInt
createdAt DateTime @default(now())
@@index([resaleListingId])
}
model EventReminder {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
sentAt DateTime @default(now())
@@unique([eventId, userId])
}
/// A sold-out `TicketType`'s waitlist. Ordering is fair by construction: FIFO
/// on `createdAt`, with a unique (ticketTypeId, userId) pair so nobody can
/// buy a second place in line, and position is always computed by counting
/// earlier-`createdAt` WAITING rows rather than a mutable counter that could
/// drift out of order.
model WaitlistEntry {
id String @id @default(uuid())
ticketType TicketType @relation(fields: [ticketTypeId], references: [id], onDelete: Cascade)
ticketTypeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
status WaitlistEntryStatus @default(WAITING)
/// Set when capacity opens up and this entry is offered a purchase window.
offeredAt DateTime?
offerExpiresAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([ticketTypeId, userId])
@@index([ticketTypeId, status, createdAt])
}
/// A discount code redeemable against primary sales for one `Event`.
model PromoCode {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
/// Stored upper-cased; lookups normalize input the same way.
code String
discountType PromoCodeDiscountType
/// Basis points (0-10000) when `discountType` is PERCENT; smallest-unit
/// amount to subtract from price when FIXED.
discountValue Int
/// Null means unlimited redemptions.
maxRedemptions Int?
redemptionCount Int @default(0)
expiresAt DateTime?
isActive Boolean @default(true)
redemptions PromoCodeRedemption[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([eventId, code])
}
/// One redemption of a `PromoCode` by a user, at most once each (the
/// unique constraint on [promoCodeId, userId] is the per-user usage limit;
/// `PromoCode.maxRedemptions` is the aggregate usage limit).
model PromoCodeRedemption {
id String @id @default(uuid())
promoCode PromoCode @relation(fields: [promoCodeId], references: [id], onDelete: Cascade)
promoCodeId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
ticket Ticket? @relation(fields: [ticketId], references: [id], onDelete: SetNull)
ticketId String? @unique
createdAt DateTime @default(now())
@@unique([promoCodeId, userId])
}
/// A physical entrance/gate at an `Event`'s venue. Check-ins are attributed
/// to one via `Ticket.checkedInGateId`.
model Gate {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
name String
checkIns Ticket[]
createdAt DateTime @default(now())
@@unique([eventId, name])
}
/// A registered check-in scanner, scoped to one `Event`. Holds a hash of an
/// opaque bearer token issued once at registration (the raw token is never
/// stored) so a device's access can be revoked independently of any staff
/// member's JWT -- see `ScannerDeviceGuard`.
model ScannerDevice {
id String @id @default(uuid())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
eventId String
name String
tokenHash String @unique
lastUsedAt DateTime?
revokedAt DateTime?
createdAt DateTime @default(now())
@@index([eventId])
}
model WebhookEndpoint {
id String @id @default(uuid())
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
organizationId String
url String
secret String
events String @default("*")
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([organizationId])
}
/// #209 — audit trail for sensitive actions (org/event writes, ticket revokes).
/// Actor, action, entity and timestamp are stored; `metadata` carries
/// optional context (e.g. ticket ids, previous status).
model AuditLog {
id String @id @default(uuid())
/// User who performed the action. Null for system/cron actors.
actorId String?
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
action String
/// E.g. "Organization", "Event", "Ticket".
entityType String
entityId String
metadata Json?
createdAt DateTime @default(now())
@@index([actorId])
@@index([entityType, entityId])
@@index([createdAt])
}
/// Records intent between a build-transaction call (e.g. `buildPurchaseTx`)
/// and its confirm call, so the window where a signed XDR exists but hasn't
/// been submitted/confirmed isn't a total black box. Rows are transient and
/// swept by `PendingTxCleanupService` once `expiresAt` has passed.
model PendingTx {
id String @id @default(uuid())
/// Discriminator for which build-transaction flow created this row, e.g.
/// "issue", "purchase", "transfer", "check-in", "revoke", "list-resale",
/// "cancel-resale", "buy-resale".
type String
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
/// Arbitrary JSON snapshot of the parameters used to build the transaction,
/// so a confirm call (or a support investigation) can inspect what was
/// intended without re-deriving it.
payload Json
expiresAt DateTime
createdAt DateTime @default(now())
@@index([expiresAt])
@@index([userId])
}
/// Signed transactions already relayed and recorded by a confirm-* endpoint,
/// keyed by the envelope hash (#159). A replayed confirm returns `response`
/// instead of re-applying the DB changes.
model ProcessedTx {
txHash String @id
operation String
response Json
createdAt DateTime @default(now())
}
/// Position of the chain event indexer in the ticketing contract's event
/// stream (#163). `cursor` is the RPC `pagingToken` of the last applied event.
model IndexerCursor {
name String @id
cursor String
updatedAt DateTime @updatedAt
}
/// Contract events the indexer already applied, keyed by the RPC event id
/// (#163). A re-delivered event hits this primary key and is skipped.
model ProcessedChainEvent {
id String @id
ledger Int
name String
processedAt DateTime @default(now())
}