Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/samirprakash/go-bank
Backend system for a simple banking application developed to be used as a boilerplate for best practices around developing and working with golang based API's, GORM with SQLC and PostgresSQL as a database.
https://github.com/samirprakash/go-bank
api ci github-actions golang golang-migrate gorm postgresql rest-api
Last synced: 2 months ago
JSON representation
Backend system for a simple banking application developed to be used as a boilerplate for best practices around developing and working with golang based API's, GORM with SQLC and PostgresSQL as a database.
- Host: GitHub
- URL: https://github.com/samirprakash/go-bank
- Owner: samirprakash
- Created: 2021-01-20T20:30:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-03T04:56:20.000Z (almost 2 years ago)
- Last Synced: 2024-06-19T03:13:33.578Z (8 months ago)
- Topics: api, ci, github-actions, golang, golang-migrate, gorm, postgresql, rest-api
- Language: Go
- Homepage:
- Size: 105 KB
- Stars: 29
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# A Simple Bank

### Features
- 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### Pre-requisites
- Install `docker for desktop`
- Execute `brew install golang-migrate sqlc`
- Execute `go install github.com/golang/mock/[email protected]`### Database Design
- Design DB schema using dbdiagram.io
- Export the queries onto `/dbdiagrams.io`
- Save and share DB diagram within the team
- Generate SQL code to create database in a target database engine i.e. postgres/MySQL/SQLServer### Docker and Postgres
- Execute `docker pull postgres:12-alpine` to get the postgres image
- Execute `docker run --name postgres12 -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:12-alpine` to run the postgres container
- Execute `docker logs postgres12` to see the logs
- Execute `docker exec -it postgres12 psql -U root` to connect to the postgres container and login as `root` user
- Connect to postgres container and execute the queries from `/dbdiagrams.io` to create the tables### DB migration
- Execute `migrate -version` to verify that the `golang-migrate` has been installed
- Execute `migrate create -ext sql -dir db/migration -seq init_schema` to generate migration files
- `*.up.sql` is used to migrate up to a new version using `migrate up`
- `*.down.sql` is used to migrate down to an older version using `migrate down`
- Copy the sql quesries generated from `dbdiagram.io` to `*.up.sql`
- Add `DROP TABLE` queries to `*.down.sql`
- Execute `make migrateup` to migrate data upwards to a new version
- Execute `make migratedown` to revert migration to a previous version
- Manage migrations in future with `migrtion up/down` commands### DB and Docker Setup for development
- Execute `make postgres` to run postgres container on local docker setup
- Execute `make createdb` to create the `simple_bank` database
- Execute `make migrateup` to setup tables and initial database state
- If required,
- Execute `make dropdb` to drop database
- Execute `make migratedown` to migrate or revert database state to a previous version### Generate CRUD Golang code from SQL
- Execute `make sqlc` to auto generate CRUD functionalities
- Execute `make mock` to generate mock DB