Mithril CMS uses PostgreSQL. The database configuration is defined in docker-compose.yml
:
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: S3cret
POSTGRES_USER: mithril
POSTGRES_DB: mithrildb
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- 5432:5432
To start the database:
docker compose up -d
sqlc generates type-safe Go code from SQL. Our project uses sqlc as follows:
-
Install sqlc:
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest
-
The
sqlc.yaml
configuration file is already in the project root. -
SQL queries are located in
internal/constant/query/query.sql
. -
Generate Go code:
sqlc generate
This will create or update files in
internal/storage/persistence/
.
migrate manages database migrations:
-
Install migrate:
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
-
Migration files are located in
db/migration/
. -
To create a new migration:
migrate create -ext sql -dir db/migration -seq <migration_name>
-
To run migrations:
migrate -database "postgresql://mithril:S3cret@localhost:5432/mithrildb?sslmode=disable" -path db/migration up
The project includes a Makefile for common tasks. Run make help
to see available commands.