This project provides a ready-to-run local development stack with:
- PostgreSQL 18 as the database
- Atlas as the database migration tool
- pgAdmin 4 as the database management UI
- PgTap the unit test framework
- Docker Compose to orchestrate all services and run migrations automatically on startup
- docker-compose.yml — Orchestrates Postgres, Atlas (schema), and pgAdmin
- atlas.hcl — Atlas configuration (connection URL and schema directory)
- schema/ — Database migration files (Golang-Migrate format)
- 00_core_init_tables.sql — Initial migration that creates the core ledger tables
- 01_create_tenant_function.sql — Function to create a new tenant
- PGTap/ — Database test files (pgTAP)
- 00_core_tables_test.sql — Tests for the core ledger schema
- .env — Default environment variables (can be customized)
- README.md — This documentation
- Docker Desktop (or Docker Engine + Docker Compose) installed and running
- Configure environment variables (optional)
- Edit .env to adjust credentials and ports if needed.
- Start the stack
- Run:
docker compose up - What will happen:
- Postgres 18 starts and becomes healthy.
- The migrate service runs "atlas migrate apply" one time and exits after applying migrations.
- pgAdmin becomes available on http://localhost:5050 (default).
- Access pgAdmin
- Open http://localhost:5050 in your browser.
- Login with:
- Email: admin@example.com (default)
- Password: admin (default)
- Add a new Server in pgAdmin:
- General
- Name: Local Postgres (any name you like)
- Connection
- Host name/address: db
- Port: 5432 (or your PGPORT if changed)
- Maintenance database: ledger (or your PGDATABASE)
- Username: postgres (or your PGUSER)
- Password: postgres (or your PGPASSWORD)
- General
- Save and connect. You should see the ledger database and (after the first run) the core tables under Schemas -> public -> Tables.
- Migration format: golang-migrate style (file names like 20250101120000_add_table.up.sql)
- Files live in: schema/
- You can author SQL directly inside schema/*.up.sql and optional *.down.sql.
- Example file names:
- schema/00_core_init_tables.sql
- The migrate service runs automatically on docker compose up. If you add new migration files or see checksum errors, run:
docker compose run --rm hashdocker compose run --rm migrate
docker compose run --rm migrate migrate status
docker compose run --rm migrate migrate down -- 1- The trailing "-- 1" tells Atlas to revert one migration. Adjust as needed.
- Tests are located in: PGTap/
- To run all tests:
docker compose run --rm pgtap
- This will:
- Ensure the database and migrations are ready.
- Install the pgtap extension (if not already present).
- Execute all .sql files in the PGTap/ directory using pg_prove.
- Press Ctrl+C in the terminal where docker compose up is running, then:
docker compose down
- Postgres data is persisted in the db_data Docker volume.
- pgAdmin state is persisted in the pgadmin_data Docker volume.
- To remove containers and volumes (CAUTION: destroys your DB data):
docker compose down -v
- .env variables (defaults shown):
- PGUSER=postgres
- PGPASSWORD=postgres
- PGDATABASE=ledger
- PGPORT=5432
- PGADMIN_DEFAULT_EMAIL=admin@example.com
- PGADMIN_DEFAULT_PASSWORD=admin
- PGADMIN_PORT=5050
- ATLAS_LOG_FORMAT=cli
- If you change credentials or DB name in .env, pgAdmin connection settings must match.
- The migrate service depends on the db healthcheck, ensuring migrations only run after Postgres is ready.
- The Atlas configuration (atlas.hcl) is set to use the Docker network host name db to connect to Postgres.
- For schema diff and declarative workflows, see Atlas docs: https://atlasgo.io/
- Port already in use:
- Change PGPORT or PGADMIN_PORT in .env and re-run docker compose up.
- Authentication failure in pgAdmin:
- Ensure your pgAdmin connection user/password matches the values in .env for Postgres.
- Update the atlas.sum file:
- Run
docker compose run --rm migrate migrate hashto generate checksums and apply:
- Run
- Migrations didn’t run:
- Check logs of the migrate service: docker compose logs migrate
- Run manually:
docker compose run --rm migrate
- Checksum error about atlas.sum:
- If you see "You have a checksum error in your schema directory" or "checksum file not found", just run the migrate service to generate checksums and apply:
docker compose run --rm migrate
- If you see "You have a checksum error in your schema directory" or "checksum file not found", just run the migrate service to generate checksums and apply:
- Reset everything (DANGER: deletes data):
docker compose down -v && docker compose up
- This sample is provided as-is. Use freely for learning or as a starting point for your projects.