Each member can pin up to four lists and pick an icon for them (per-user settings on shopping_list_members, PATCH /api/lists/:listId/preferences). Pinned lists stay visible with their pending count, kept live over each list's SSE stream: a chip bar above the bottom nav on mobile and a "Fijadas" group in the sidebar on desktop. GET /api/lists now returns pendingCount, isPinned and icon. The page padding, install prompt and dictation button now read --bottom-nav-height, which grows with the pinned bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
217 lines
7.7 KiB
Plaintext
217 lines
7.7 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[]
|
|
passkeys Passkey[]
|
|
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")
|
|
}
|
|
|
|
// WebAuthn credentials registered through the BetterAuth passkey plugin.
|
|
// `credentialID` is the raw credential id and `publicKey` the stored public key;
|
|
// the plugin reads and writes these rows directly, so keep the column names it
|
|
// expects (mapped to snake_case like the rest of the schema).
|
|
model Passkey {
|
|
id String @id
|
|
name String?
|
|
publicKey String @map("public_key")
|
|
userId String @map("user_id")
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
credentialID String @map("credential_id")
|
|
counter Int
|
|
deviceType String @map("device_type")
|
|
backedUp Boolean @map("backed_up")
|
|
transports String?
|
|
createdAt DateTime? @default(now()) @map("created_at")
|
|
aaguid String?
|
|
|
|
@@index([userId])
|
|
@@index([credentialID])
|
|
@@map("passkeys")
|
|
}
|
|
|
|
// --- 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")
|
|
/// Per user: the list is pinned to the always-visible bar (at most 4 per user).
|
|
isPinned Boolean @default(false) @map("is_pinned")
|
|
/// Position among the user's pinned lists (pin order); null when not pinned.
|
|
pinnedOrder Int? @map("pinned_order")
|
|
/// Per user: key of the icon chosen for the list (see `LIST_ICONS` in `@superlist/shared`).
|
|
icon String?
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@unique([listId, userId])
|
|
@@index([userId, isPrimary])
|
|
@@index([userId, isPinned])
|
|
@@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")
|
|
}
|