# Database

## PostgreSQL

- Local: Docker container
- Prod: Fly.io Managed Postgres

## Schema

- LOCAL is the source of truth
- Migrations live in /database/migrations/YYYYMMDD_description.sql

## Local connection

- Port: defined in docker-compose
- Credentials: .env.example

## Production connection

- Via Fly.io tunnel
- Managed: flyctl postgres connect -a [db-app]
- Unmanaged: fly proxy [local-port]:5432 -a [db-app]

## Migration workflow

1. Create a file under migrations/
2. Apply locally
3. Test
4. Open a tunnel to PROD
5. Apply on PROD
6. Verify
7. Close the tunnel
8. Commit
