- Create and manage account
- Owner
- Balance
- Currency
- Record all balance changes for each account
- Create an account entry for each change for each account
- Money transfer transaction
- Perform money transfer between 2 accounts consistently within a transaction
- Install
docker for desktop - Execute
brew install golang-migrate sqlc - Execute
go install github.com/golang/mock/[email protected]
- Design DB schema using dbdiagram.io
- Export the queries onto
/dbdiagrams.io
- Export the queries onto
- Save and share DB diagram within the team
- Generate SQL code to create database in a target database engine i.e. postgres/MySQL/SQLServer
- Execute
docker pull postgres:12-alpineto get the postgres image - Execute
docker run --name postgres12 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:12-alpineto run the postgres container - Execute
docker logs postgres12to see the logs - Execute
docker exec -it postgres12 psql -U rootto connect to the postgres container and login asrootuser - Connect to postgres container and execute the queries from
/dbdiagrams.ioto create the tables
- Execute
migrate -versionto verify that thegolang-migratehas been installed - Execute
migrate create -ext sql -dir db/migration -seq init_schemato generate migration files*.up.sqlis used to migrate up to a new version usingmigrate up*.down.sqlis used to migrate down to an older version usingmigrate down- Copy the sql quesries generated from
dbdiagram.ioto*.up.sql - Add
DROP TABLEqueries to*.down.sql
- Execute
make migrateupto migrate data upwards to a new version - Execute
make migratedownto revert migration to a previous version - Manage migrations in future with
migrtion up/downcommands
- Execute
make postgresto run postgres container on local docker setup - Execute
make createdbto create thesimple_bankdatabase - Execute
make migrateupto setup tables and initial database state - If required,
- Execute
make dropdbto drop database - Execute
make migratedownto migrate or revert database state to a previous version
- Execute
- Execute
make sqlcto auto generate CRUD functionalities - Execute
make mockto generate mock DB