feat: add collaborative shopping lists with items and invitations
Some checks failed
CI / Verify (push) Has been cancelled
Some checks failed
CI / Verify (push) Has been cancelled
API: lists, items and invitations modules (list, create, get, update, set-primary, items create/list, invitation create/accept/list-pending), BetterAuth session helper, list membership, mailer and Prisma schema plus migrations. Web: lists overview, list detail (items) and list management (settings) views, item and invitation forms/hooks, sign-up and invitation accept pages. Shared: shopping list DTOs. Tooling: ignore the generated TanStack Router cache (apps/web/.tanstack).
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
// 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`.
|
||||
|
||||
@@ -14,67 +21,164 @@ generator client {
|
||||
|
||||
// --- BetterAuth core models -------------------------------------------------
|
||||
// Shape generated by `bunx @better-auth/cli generate`. Keep in sync with the
|
||||
// fields the auth config expects.
|
||||
// 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)
|
||||
emailVerified Boolean @default(false) @map("email_verified")
|
||||
image String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
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("user")
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
model Session {
|
||||
id String @id
|
||||
expiresAt DateTime
|
||||
expiresAt DateTime @map("expires_at")
|
||||
token String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
ipAddress String?
|
||||
userAgent String?
|
||||
userId 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("session")
|
||||
@@map("sessions")
|
||||
}
|
||||
|
||||
model Account {
|
||||
id String @id
|
||||
accountId String
|
||||
providerId String
|
||||
userId String
|
||||
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?
|
||||
refreshToken String?
|
||||
idToken String?
|
||||
accessTokenExpiresAt DateTime?
|
||||
refreshTokenExpiresAt DateTime?
|
||||
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())
|
||||
updatedAt DateTime @updatedAt
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([userId])
|
||||
@@map("account")
|
||||
@@map("accounts")
|
||||
}
|
||||
|
||||
model Verification {
|
||||
id String @id
|
||||
identifier String
|
||||
value String
|
||||
expiresAt DateTime
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
expiresAt DateTime @map("expires_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([identifier])
|
||||
@@map("verification")
|
||||
@@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)
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user