To update the database schema to a new version, create schema migration files for postgres and sqlite as described here.
all migrations must run within a transaction, so migration files must be wrapped with
BEGIN;
andCOMMIT;
statements
- postgreSQL migration files can be added to main/adapters/database/postgres/migrations
- SQLite migration files can be added to main/adapters/database/sqlite/migrations
The migration will be executed automatically on application startup or can be triggered independently using a CLI.
Steps to generate functions for database access:
- Prerequisite: install sqlc
- add postgreSQL query to
main/adapters/database/postgres/queries
and SQLite query tomain/adapters/database/sqlite/queries
- run
cd main/adapters/database && go generate
- extend the
Querier
interface inmain/adapters/database/querier.go
with new function - implement new wrapper for generated postgres function in
main/adapters/database/db_postgres.go
and new wrapper for generated sqlite function inmain/adapters/database/db_sqlite.go