This project is a small example of implementing an event-sourced e-commerce web application using Go and Postgres. The different parts of the application are meant to be reused for later projects as building blocks.
Database credentials for local development are defined in the .env.dev
file. To source these into your environment, use:
set -o allexport && source .env.dev && set +o allexport
For local development, you can use the included docker-compose.yaml
file to start a Postgres server. The same server will be used to run integration tests, but with randomly generated database names to make it possible to run integration tests concurrently.
First, you'll want to start up the containers:
podman compose up -d
To test the system in a live environment, you'll need to run migrations on the previously started database. The project uses tern to manage migrations. To migrate to the latest version, you can run the following commands:
tern migrate --migrations ./db/migrations --config ./db/tern.conf
If you ever need to revert a single migration, you can do:
tern migrate -d -1 --migrations ./db/migrations --config ./db/tern.conf
The project uses sqlc to generate type-safe Go code from SQL queries. The query definitions live under db/queries
. You can update the generated files by running:
sqlc generate -f ./db/sqlc.yaml
The integration tests defined in the project require a running instance of Postgres. Once it is up and running, execute integration tests with:
go test -v ./tests/...