126 lines
3.3 KiB
Plaintext
126 lines
3.3 KiB
Plaintext
datasource db {
|
|
provider = "sqlite"
|
|
url = env("DATABASE_URL")
|
|
}
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
model Voucher {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
anbieter String
|
|
wertCents Int
|
|
restCents Int
|
|
ablaufdatum DateTime?
|
|
codeText String?
|
|
kategorie String?
|
|
notiz String?
|
|
providerDomain String?
|
|
createdBy String?
|
|
shopUrl String?
|
|
wertTyp String @default("euro")
|
|
prozentWert Int?
|
|
mindestbestellwertCents Int?
|
|
ownerId Int @default(0)
|
|
owner User @relation("VoucherOwner", fields: [ownerId], references: [id])
|
|
householdId Int?
|
|
household Household? @relation(fields: [householdId], references: [id])
|
|
status String @default("aktiv")
|
|
contacts VoucherContact[]
|
|
rules ReminderRule[]
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
model Contact {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
email String?
|
|
telegramChatId String?
|
|
ownerId Int @default(0)
|
|
owner User @relation("ContactOwner", fields: [ownerId], references: [id])
|
|
householdId Int?
|
|
household Household? @relation(fields: [householdId], references: [id])
|
|
vouchers VoucherContact[]
|
|
}
|
|
model VoucherContact {
|
|
voucherId Int
|
|
contactId Int
|
|
voucher Voucher @relation(fields: [voucherId], references: [id], onDelete: Cascade)
|
|
contact Contact @relation(fields: [contactId], references: [id], onDelete: Cascade)
|
|
@@id([voucherId, contactId])
|
|
}
|
|
model ReminderRule {
|
|
id Int @id @default(autoincrement())
|
|
voucherId Int
|
|
tageVorher Int
|
|
voucher Voucher @relation(fields: [voucherId], references: [id], onDelete: Cascade)
|
|
logs NotificationLog[]
|
|
@@unique([voucherId, tageVorher])
|
|
}
|
|
model NotificationLog {
|
|
id Int @id @default(autoincrement())
|
|
ruleId Int
|
|
kanal String
|
|
empfaenger String
|
|
zielDatum String
|
|
status String
|
|
fehler String?
|
|
sentAt DateTime @default(now())
|
|
rule ReminderRule @relation(fields: [ruleId], references: [id], onDelete: Cascade)
|
|
@@unique([ruleId, kanal, empfaenger, zielDatum])
|
|
}
|
|
|
|
model AppSetting {
|
|
key String @id
|
|
value String
|
|
updatedAt DateTime @updatedAt
|
|
}
|
|
|
|
model Household {
|
|
id Int @id @default(autoincrement())
|
|
name String @unique
|
|
createdAt DateTime @default(now())
|
|
members HouseholdMember[]
|
|
vouchers Voucher[]
|
|
contacts Contact[]
|
|
invites Invite[]
|
|
}
|
|
|
|
model HouseholdMember {
|
|
id Int @id @default(autoincrement())
|
|
householdId Int
|
|
household Household @relation(fields: [householdId], references: [id], onDelete: Cascade)
|
|
userId Int @unique
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
role String @default("member")
|
|
createdAt DateTime @default(now())
|
|
@@unique([householdId, userId])
|
|
}
|
|
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
name String
|
|
email String? @unique
|
|
passwordHash String?
|
|
role String @default("member")
|
|
oidcSubject String? @unique
|
|
tokenVersion Int @default(0)
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
membership HouseholdMember?
|
|
ownedVouchers Voucher[] @relation("VoucherOwner")
|
|
ownedContacts Contact[] @relation("ContactOwner")
|
|
}
|
|
|
|
model Invite {
|
|
id Int @id @default(autoincrement())
|
|
email String @unique
|
|
tokenHash String @unique
|
|
role String @default("member")
|
|
householdId Int?
|
|
household Household? @relation(fields: [householdId], references: [id], onDelete: Cascade)
|
|
expiresAt DateTime
|
|
acceptedAt DateTime?
|
|
createdAt DateTime @default(now())
|
|
}
|