Skip to main content

Database

PostgreSQL 17. Locally it runs in Docker Compose; staging and prod will use RDS. Alembic migrations are the only way the schema changes, everywhere.

The schema holds only what the frontend uses today: trips, their dates and destination, and who is on each one. New tables arrive with the screens that need them.

Schema​

Models live in apps/backend/app/models/. Every table records when its rows were created (created_at, or joined_at on trip_members), with a database default. Mutable tables also get updated_at; SQLAlchemy bumps it on ORM updates, but raw SQL and bulk update() statements must set it themselves.

How it maps to the frontend​

GET /trips and GET /trips/{id} return exactly the Trip type in apps/frontend/src/data/trips.ts:

Frontend fieldComes from
idtrips.id (a UUID string)
name, destinationtrips.name, trips.destination
startDate, endDatetrips.start_date, trips.end_date (YYYY-MM-DD)
membersusers.display_name for each trip_members row, ordered by joined_at

There is no login yet, so GET /trips returns every trip. Once auth exists it will return only the current user's trips, filtered through trip_members.

Roles​

apps/backend/db/init/01-roles.sh runs once, when the Docker volume is first created:

RoleUsed byRights
postgresYou, via .\vesper db-shellSuperuser; emergencies only
vesper_migratorAlembicOwns the public schema; DDL
vesper_appThe APISELECT/INSERT/UPDATE/DELETE on tables; no DDL (a test checks this)

If you change the init script, recreate the volume: .\vesper db-destroy, then .\vesper setup.

Changing the schema​

  1. Edit or add models in app/models/. A new model file must be imported in app/models/__init__.py, or Alembic won't see it.
  2. Run .\vesper makemigration "add trip cover photo".
  3. Read the generated file in migrations/versions/. Autogenerate misses some things: renames (it sees a drop plus an add), enum value changes, and dropping enum types in downgrade.
  4. Run .\vesper reset-db to prove that both upgrade and downgrade work.
  5. Commit the model change and the migration in the same PR.

Rules​

  • Never edit a migration that has been merged. Write a new one.
  • Never change the database by hand.
  • Expand, migrate, contract. Add columns as nullable or with a default, backfill, and only drop old columns in a later release. Old app builds keep calling the API for weeks.
  • One migration per PR where possible, so reviews stay readable.

Seed data​

scripts/seed.py creates the same two trips as the frontend's sample data: Lisbon weekend (Joe, Sam, Priya) and Alps ski trip (Joe, Sam). The app therefore looks the same whether it reads the sample file or the API. The script refuses to run on a non-empty database, so use .\vesper reset-db to start fresh.

Planned​

These come with the features that need them, following the infrastructure plan: itinerary events, expenses with splits (money as integer minor units, with a currency and an FX rate frozen at expense time), member roles, idempotency keys for create requests, and pgvector for the AI agent.