Tapping an item in the list toggles it via a new PATCH /lists/:listId/items/:itemId endpoint. Marking an item as bought stores boughtAt (for future stats) and clearing it back to pending resets the timestamp. The web app updates optimistically and each row is now a real button with aria-pressed.
186 lines
6.4 KiB
Plaintext
186 lines
6.4 KiB
Plaintext
// Prisma schema. Docs: https://pris.ly/d/prisma-schema
|
|
//
|
|
// Naming convention (see AGENTS.md): tables are plural snake_case
|
|
// (`shopping_lists`, `users`), columns are snake_case (`created_at`,
|
|
// `owner_id`) and enum types are snake_case (`list_role`), declared through
|
|
// `@@map` / `@map`. The Prisma *model* and *field* names stay PascalCase /
|
|
// camelCase because BetterAuth and the generated client address models by
|
|
// those names.
|
|
//
|
|
// After editing this file run `bun run db:migrate` (creates + applies a migration)
|
|
// and commit the generated migration under `prisma/migrations`.
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
generator client {
|
|
provider = "prisma-client"
|
|
output = "../src/generated/prisma"
|
|
}
|
|
|
|
// --- BetterAuth core models -------------------------------------------------
|
|
// Shape generated by `bunx @better-auth/cli generate`. Keep in sync with the
|
|
// fields the auth config expects, and keep the snake_case mapping below if you
|
|
// regenerate it.
|
|
|
|
model User {
|
|
id String @id
|
|
name String
|
|
email String
|
|
emailVerified Boolean @default(false) @map("email_verified")
|
|
image String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
sessions Session[]
|
|
accounts Account[]
|
|
ownedLists ShoppingList[] @relation("ListOwner")
|
|
memberships ShoppingListMember[]
|
|
invitations ShoppingListInvitation[] @relation("InvitedBy")
|
|
|
|
@@unique([email])
|
|
@@map("users")
|
|
}
|
|
|
|
model Session {
|
|
id String @id
|
|
expiresAt DateTime @map("expires_at")
|
|
token String
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
ipAddress String? @map("ip_address")
|
|
userAgent String? @map("user_agent")
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([token])
|
|
@@index([userId])
|
|
@@map("sessions")
|
|
}
|
|
|
|
model Account {
|
|
id String @id
|
|
accountId String @map("account_id")
|
|
providerId String @map("provider_id")
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
accessToken String? @map("access_token")
|
|
refreshToken String? @map("refresh_token")
|
|
idToken String? @map("id_token")
|
|
accessTokenExpiresAt DateTime? @map("access_token_expires_at")
|
|
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
|
|
scope String?
|
|
password String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([userId])
|
|
@@map("accounts")
|
|
}
|
|
|
|
model Verification {
|
|
id String @id
|
|
identifier String
|
|
value String
|
|
expiresAt DateTime @map("expires_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([identifier])
|
|
@@map("verifications")
|
|
}
|
|
|
|
// --- Domain models ----------------------------------------------------------
|
|
|
|
/// A collaborative shopping list. Membership (and therefore access) lives in
|
|
/// `ShoppingListMember`, not in this table.
|
|
model ShoppingList {
|
|
id String @id @default(uuid())
|
|
name String
|
|
ownerId String @map("owner_id")
|
|
owner User @relation("ListOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
|
members ShoppingListMember[]
|
|
invitations ShoppingListInvitation[]
|
|
items ListItem[]
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@index([ownerId])
|
|
@@map("shopping_lists")
|
|
}
|
|
|
|
model ListItem {
|
|
id String @id @default(cuid())
|
|
shoppingListId String @map("shopping_list_id")
|
|
name String
|
|
completed Boolean @default(false)
|
|
boughtAt DateTime? @map("bought_at")
|
|
quantity String? @map("quantity")
|
|
notes String? @map("notes")
|
|
order Int @default(0) @map("order")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
shoppingList ShoppingList @relation(fields: [shoppingListId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([shoppingListId, order])
|
|
@@map("list_items")
|
|
}
|
|
|
|
enum ListRole {
|
|
owner
|
|
collaborator
|
|
|
|
@@map("list_role")
|
|
}
|
|
|
|
/// Join table between a user and a list. `isPrimary` is per user: each person
|
|
/// picks their own main list among the ones they belong to.
|
|
model ShoppingListMember {
|
|
id String @id @default(uuid())
|
|
listId String @map("list_id")
|
|
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
role ListRole @default(collaborator)
|
|
isPrimary Boolean @default(false) @map("is_primary")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([listId, userId])
|
|
@@index([userId, isPrimary])
|
|
@@map("shopping_list_members")
|
|
}
|
|
|
|
enum InvitationStatus {
|
|
pending
|
|
accepted
|
|
revoked
|
|
expired
|
|
|
|
@@map("invitation_status")
|
|
}
|
|
|
|
/// Pending or historical invitation of an email address to a list. When the
|
|
/// email already belongs to a user the membership is created immediately and
|
|
/// this record is stored as `accepted` for history.
|
|
model ShoppingListInvitation {
|
|
id String @id @default(uuid())
|
|
listId String @map("list_id")
|
|
list ShoppingList @relation(fields: [listId], references: [id], onDelete: Cascade)
|
|
email String
|
|
token String
|
|
status InvitationStatus @default(pending)
|
|
invitedById String @map("invited_by_id")
|
|
invitedBy User @relation("InvitedBy", fields: [invitedById], references: [id], onDelete: Cascade)
|
|
expiresAt DateTime @map("expires_at")
|
|
acceptedAt DateTime? @map("accepted_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([token])
|
|
@@index([listId, status])
|
|
@@index([email, status])
|
|
@@map("shopping_list_invitations")
|
|
}
|