-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
47 lines (37 loc) · 1.42 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
# Load environment variables from .env file
include .env
export $(shell sed 's/=.*//' .env)
.PHONY: create-database
.PHONY: drop-database
.PHONY: create-migration
create-database:
@if PGPASSWORD=$(DB_PASSWORD) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -lqt | cut -d \| -f 1 | grep -qw $(DB_NAME); then \
echo "Database already exists"; \
else \
PGPASSWORD=$(DB_PASSWORD) createdb -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) $(DB_NAME); \
echo "Database created"; \
fi
drop-database:
@if ! PGPASSWORD=$(DB_PASSWORD) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -lqt | cut -d \| -f 1 | grep -qw $(DB_NAME); then \
echo "Database does not exist"; \
else \
PGPASSWORD=$(DB_PASSWORD) dropdb -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) $(DB_NAME); \
echo "Database dropped"; \
fi
create-migration:
$(eval NAME := $(filter-out $@,$(MAKECMDGOALS)))
$(eval FILENAME := $(shell date +'%Y%m%d%H%M%S')_$(name))
./dev-tools/migration_template.sh $(FILENAME) $(name)
migrate:
PGPASSWORD=$(DB_PASSWORD) migrate -path ./migrations -database "postgres://$(DB_USER)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" up
rollback:
PGPASSWORD=$(DB_PASSWORD) migrate -path ./migrations -database "postgres://$(DB_USER)@$(DB_HOST):$(DB_PORT)/$(DB_NAME)?sslmode=disable" down -all
up:
docker-compose up --build -d
docker-compose logs -f e-commerce
down:
docker-compose down
stop:
docker stop e-commerce
start:
docker start e-commerce