No results
1
Datenbank
mrrmlab Wiki edited this page 2026-05-02 18:03:36 +02:00
Datenbank
Stack
- Datenbank: PostgreSQL 16+ (Dev) / 17 Alpine (Produktion)
- ORM: Drizzle ORM (typsicher, compile-time SQL)
- Migrations: drizzle-kit
Schema-Übersicht
Barrel-Export: apps/api/src/db/schema.ts
Pro-Feature: apps/api/src/modules/<feature>/<feature>.schema.ts
stores
| Spalte | Typ | Beschreibung |
|---|---|---|
id |
uuid (PK) | |
ownerSub |
text | Keycloak User-ID |
name |
text | Name des Geschäfts |
details |
jsonb | Flexible Metadaten |
createdAt, updatedAt |
timestamptz |
lists
| Spalte | Typ | Beschreibung |
|---|---|---|
id |
uuid (PK) | |
ownerSub |
text | Keycloak User-ID |
type |
enum | shopping | todo | notes |
title |
text | |
storeId |
uuid (FK → stores, nullable) | |
createdAt, updatedAt |
timestamptz |
listItems
| Spalte | Typ | Beschreibung |
|---|---|---|
id |
uuid (PK) | |
listId |
uuid (FK → lists, cascade delete) | |
position |
integer | Reihenfolge |
data |
jsonb | Typspezifische Payload |
createdAt, updatedAt |
timestamptz |
mailAccounts, mailFolders, mailMessagesCache
E-Mail-Module — IMAP-Konten, Ordner und gecachte Nachrichten.
Migrations-Workflow
# 1. Schema in TypeScript ändern (z.B. neue Spalte)
# apps/api/src/modules/<feature>/<feature>.schema.ts
# 2. Migration generieren
pnpm -F @mrrmlab/api db:generate
# → Erstellt SQL in drizzle/migrations/
# 3. Migration anwenden (lokal)
pnpm -F @mrrmlab/api db:migrate
# 4. Schema committen + Migration-SQL committen
In Produktion wird db:migrate automatisch beim API-Start ausgeführt (main.ts).
Drizzle Studio
pnpm -F @mrrmlab/api db:studio
# → Öffnet Web-UI unter http://localhost:4983
Lokal (Docker)
docker compose -f apps/api/docker-compose.yml up -d
# Datenbank: mrrmlab | User: mrrmlab | Passwort: mrrmlab | Port: 5432