-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
347dc46
commit 7e7e6a8
Showing
1 changed file
with
106 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,109 @@ | ||
# Simple Bank | ||
|
||
## DB Schema | ||
This repository contains code for a simple bank service written completely in Go, supporting the following operations: | ||
|
||
https://dbdiagram.io/d/Simple-Bank-650d067f02bd1c4a5e0e347d | ||
1. Create and manage bank accounts, which are composed of owner’s name, balance, and currency. | ||
2. Record all balance changes to each of the account. So every time some money is added to or subtracted from the account, an account entry record will be created. | ||
3. Perform a money transfer between 2 accounts. This should happen within a transaction, so that either both accounts’ balance are updated successfully or none of them are. | ||
|
||
## Setup local development | ||
|
||
### Install tools | ||
|
||
- [Docker desktop](https://www.docker.com/products/docker-desktop) | ||
- [TablePlus](https://tableplus.com/) | ||
- [Golang](https://golang.org/) | ||
- [Homebrew](https://brew.sh/) | ||
- [Migrate](https://github.com/golang-migrate/migrate/tree/master/cmd/migrate) | ||
|
||
```bash | ||
brew install golang-migrate | ||
``` | ||
|
||
- [Sqlc](https://github.com/kyleconroy/sqlc#installation) | ||
|
||
```bash | ||
brew install sqlc | ||
``` | ||
|
||
- [Gomock](https://github.com/golang/mock) | ||
|
||
```bash | ||
go install github.com/golang/mock/[email protected] | ||
``` | ||
|
||
### Setup infrastructure | ||
|
||
- Start postgres container: | ||
|
||
```bash | ||
make postgres | ||
``` | ||
|
||
- Create simple_bank database: | ||
|
||
```bash | ||
make createdb | ||
``` | ||
|
||
- Run db migration up all versions: | ||
|
||
```bash | ||
make migrateup | ||
``` | ||
|
||
- Run db migration up 1 version: | ||
|
||
```bash | ||
make migrateup1 | ||
``` | ||
|
||
- Run db migration down all versions: | ||
|
||
```bash | ||
make migratedown | ||
``` | ||
|
||
- Run db migration down 1 version: | ||
|
||
```bash | ||
make migratedown1 | ||
``` | ||
|
||
### Documentation | ||
|
||
- DB Schema: | ||
|
||
https://dbdiagram.io/d/Simple-Bank-650d067f02bd1c4a5e0e347d | ||
|
||
- API Schema: | ||
|
||
https://github.com/viralparmarme/simple-bank/blob/main/postman.json | ||
|
||
### How to generate code | ||
|
||
- Generate SQL CRUD with sqlc: | ||
|
||
```bash | ||
make sqlc | ||
``` | ||
|
||
- Generate DB mock with gomock: | ||
|
||
```bash | ||
make mock | ||
``` | ||
|
||
### How to run | ||
|
||
- Run server: | ||
|
||
```bash | ||
make server | ||
``` | ||
|
||
- Run test: | ||
|
||
```bash | ||
make test | ||
``` |