Przejdź do głównej zawartości

Schemat bazy danych

CakeMarket wykorzystuje SQLite poprzez Drizzle ORM z driverem better-sqlite3.

Konfiguracja

  • ORM: Drizzle ORM
  • Driver: better-sqlite3
  • Plik konfiguracyjny: drizzle.config.ts
  • Lokalizacja schematu: src/lib/db/schema.ts
  • Identyfikatory: UUID v4 dla wszystkich kluczy głównych
  • Ceny: Przechowywane jako liczby całkowite w groszach (1/100 PLN)

Główne tabele

Users (Użytkownicy)

  • id (UUID, PK)
  • name, email, phone, imageUrl
  • role (user, admin)
  • Pola związane z uwierzytelnianiem

Organisations (Organizacje)

  • id (UUID, PK)
  • name, address, locationLat, locationLng
  • contactEmail, contactPhone, profileImageUrl
  • isActive (automatycznie po uzupełnieniu wymaganych danych i onboardingu Stripe)
  • isDisabled (blokada platformy niezależna od konfiguracji sprzedającego)
  • Możliwości: acceptedCakeTypes, acceptedTastes, specialRequirements
  • Operacje: leadTimeDays, deliveryEnabled, deliveryRangeKm, pickupEnabled
  • minDepositPercent (20-100)
  • Stripe: stripeAccountId, stripeOnboardingComplete
  • Opcjonalny przegląd odznaki: publiczne certificationLevel; prywatne sanepidCertDocUrl i sanepidCertExpiry (wyłącznie administratorzy Organizacji i platformy)

Organisation Members (Członkowie organizacji)

  • organisationId, userId (klucz złożony)
  • role (admin, baker)
  • status (pending, active, rejected)
  • joinedAt

Requests (Zapytania o tort)

  • id (UUID, PK)
  • buyerId lub guestToken
  • eventType, servings, desiredDate
  • deliveryMethod, deliveryAddress
  • fillings, dietaryRequirements
  • themeDescription, cakeImageUrl
  • isReorder, originalOrderId, targetOrganisationId
  • status (active, expired)
  • expiresAt

Offers (Oferty)

  • id (UUID, PK)
  • requestId, organisationId
  • price (grosze), depositPercent
  • message, proposedImageUrl, proposedImageSource
  • status (pending, accepted, withdrawn)
  • holdExpiresAt

Orders (Zamówienia)

  • id (UUID, PK)
  • orderNumber
  • requestId, offerId, organisationId, buyerId
  • totalPrice (grosze), depositAmount, balanceAmount
  • status (deposit_paid, in_progress, ready, delivered, completed, cancelled; disputed pozostaje wyłącznie dla zgodności starszych danych i nie jest aktywnym procesem)
  • balancePaidAt, balancePaymentMethod
  • cancelledBy, cancelReason
  • Znaczniki czasu: depositPaidAt, startedAt, readyAt, deliveredAt, completedAt

Payments (Płatności)

  • id (UUID, PK)
  • orderId, organisationId
  • type (deposit, balance, refund)
  • amount (grosze), netAmount
  • status (pending, succeeded, failed, refunded)
  • stripePaymentIntentId
  • method (stripe, cash, card_at_pickup)

Messages (Wiadomości)

  • id (UUID, PK)
  • orderId lub offerId
  • senderId, senderType (buyer, seller)
  • content
  • readAt

Reviews (Opinie)

  • id (UUID, PK)
  • orderId, buyerId, organisationId
  • rating (1-5), comment

Portfolio Items (Elementy portfolio)

  • id (UUID, PK)
  • organisationId
  • imageUrl, caption
  • sortOrder

Notifications (Powiadomienia)

  • id (UUID, PK)
  • userId
  • title, body
  • type
  • readAt

Migracje

Drizzle obsługuje migracje. Uruchom:

npx drizzle-kit generate
npx drizzle-kit migrate