1
Database and Migrations
Nico edited this page 2026-05-26 00:31:28 -07:00
Database and Migrations
Fiddy uses an external on-prem Postgres database. Do not add or assume a database container.
Canonical Migration Directory
Canonical migrations live in:
packages/db/migrations
Legacy SQL under backend/migrations is reference-only. Do not add new canonical migrations there.
Required Environment
Migration commands need:
DATABASE_URLset in the shell.psqlinstalled and available onPATH.- The command run from the repo root.
Do not print or commit the value of DATABASE_URL.
Commands
Show status:
npm run db:migrate:status
Create a migration:
npm run db:migrate:new -- <migration-name>
Apply pending migrations:
npm run db:migrate
Verify clean state:
npm run db:migrate:verify
Check stale legacy SQL:
npm run db:migrate:stale:check
Update stale tracking:
npm run db:migrate:stale
Operator Flow
- Confirm which database
DATABASE_URLtargets. - Run
npm run db:migrate:status. - Create a new migration file if the code change needs schema changes.
- Review the SQL.
- Apply pending migrations only when the operator intends to change that database.
- Run
npm run db:migrate:verify. - Run the relevant app tests/builds.
Tracking Table
Applied migrations are recorded in:
schema_migrations(filename text unique, applied_at timestamptz)
Migrations apply in lexicographic filename order.
Current Data Areas
The current app stores data for:
- Users and DB-backed sessions.
- Households and household members.
- Invite links, join requests, join policy, and audit events.
- Stores, household stores, locations, and zones.
- Location-scoped list items.
- Available/catalog items.
- Item images and metadata.
- Item classification and notes.
Safety Rules
- Never run migrations against production/shared data unless explicitly asked.
- Never edit applied migration history manually unless performing a planned database repair.
- Do not log secrets, DB URLs, tokens, cookies, receipt bytes, or full invite codes.
- Invite-code logging may include last 4 characters only.
- Add tests for API behavior that depends on a new schema contract.