-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
34 lines (28 loc) · 1 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
SHELL := /usr/bin/env bash
include ./backend/.env
PSQL=psql -h localhost
DB_NAME=${POSTGRES_DATABASE}
DB_SCHEMA=${POSTGRES_SCHEMA}
.PHONY: create_db
create_db: ## Ensure that the $(DB_NAME) database exists
create_db:
@$(PSQL) -d postgres -tc "SELECT count(*) FROM pg_database WHERE datname = '$(DB_NAME)'" | \
grep -q 1 || \
$(PSQL) -d postgres -c "CREATE DATABASE $(DB_NAME)";
.PHONY: drop_db
drop_db: ## Drop the $(DB_NAME) database if it exists
drop_db:
@$(PSQL) -d postgres -tc "SELECT count(*) FROM pg_database WHERE datname = '$(DB_NAME)'" | \
grep -q 0 || \
$(PSQL) -d postgres -c "DROP DATABASE $(DB_NAME)";
.PHONY: migrate
migrate: ## create the migrations
migrate:
## TODO:: this is a very basic setup, we should use flyway for migrations
for file in ./migrations/sql/*.sql; do \
printf "Applying migration: ${DB_NAME}/$$(basename $$file)\n"; \
$(PSQL) -d $(DB_NAME) -f $$file; \
done
.PHONY: reset_db
reset_db: ## Drop and recreate the $(DB_NAME) database
reset_db: drop_db create_db migrations