-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
77 lines (62 loc) · 2.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
DB_USER=root
DB_PASSWORD=testpass
DB_NAME=simplebank
DB_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:5432/${DB_NAME}?sslmode=disable
DB_CONTAINER=postgres15
## db_docs: generate dbdocs view
db_docs:
@echo "generating dbdocs view..."
dbdocs build doc/db.dbml
## db_schema: convert a dbml file to sql
db_schema:
@echo "converting a dbml file to sql..."
dbml2sql doc/db.dbml --postgres -o doc/schema.sql
## postgres: run postgres container
postgres:
@echo "running postgres container..."
docker run --name ${DB_CONTAINER} -p 5432:5432 -e POSTGRES_USER=${DB_USER} -e POSTGRES_PASSWORD=${DB_PASSWORD} -d postgres:15.2-alpine
## createdb: create a database
createdb:
@echo "creating ${DB_NAME} database..."
docker exec -it ${DB_CONTAINER} createdb --username=root --owner=root ${DB_NAME}
## dropdb: delete a database
dropdb:
@echo "deleting ${DB_NAME} database..."
docker exec -it ${DB_CONTAINER} dropdb ${DB_NAME}
## create_migration: create migration up & down files
create_migration:
@echo "creating migration files..."
migrate create -ext sql -dir db/migration -seq ${name}
## migrateup: apply all up migrations
migrateup:
@echo "applying all up migrations..."
migrate -path db/migration -database ${DB_URL} -verbose up
## migrateup: apply last up migration
migrateup1:
@echo "applying last up migration..."
migrate -path db/migration -database ${DB_URL} -verbose up 1
## migratedown: apply all down migrations
migratedown:
@echo "applying all down migrations..."
migrate -path db/migration -database ${DB_URL} -verbose down
## migratedown: apply last down migration
migratedown1:
@echo "applying last down migration..."
migrate -path db/migration -database ${DB_URL} -verbose down 1
## sqlc: generate Go code from SQL
sqlc:
@echo "generating go code from sql"
sqlc generate
## test: test the project
test:
@echo "testing"
go test -v -cover ./...
## server: start the HTTP server
server:
@echo "starting the HTTP server"
go run main.go
## mock: generates mock interfaces
mock:
@echo "generating mock interfaces..."
mockgen -package mockdb -destination db/mock/store.go github.com/foyez/simplebank/db/sqlc Store
.PHONY: db_docs db_schema postgres createdb dropdb create_migration migrateup migratedown migrateup1 migratedown1 sqlc test server mock