BINDIR=${CURDIR}/../bin
PACKAGE=route256/loms
MIGRATIONS_FOLDER	:= ./db/migrations/
LOCAL_DB_NAME		:= route256
LOCAL_DB_DSN		:= postgresql://user:password@192.168.64.4:5433/route256?sslmode=disable

PROD_USER := loms-user
PROD_PASS := loms-password
PROD_DB   := postgres-master

PROD_MIGRATIONS := ./loms/db/migrations/

bindir:
	mkdir -p ${BINDIR}

build: bindir
	echo "build loms"
	go build -o ${BINDIR}/loms cmd/server/main.go

# Used for CI
run-migrations:
	$(GOOSE) -dir $(PROD_MIGRATIONS) postgres "postgresql://$(PROD_USER):$(PROD_PASS)@$(PROD_DB):5432/loms_db?sslmode=disable" up

db-create-migration:
	$(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) create -s $(n) sql

db-migrate:
	$(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) postgres "$(LOCAL_DB_DSN)" up

db-migrate-down:
	$(BINDIR)/goose -dir $(MIGRATIONS_FOLDER) postgres "$(LOCAL_DB_DSN)" down

db-reset-local:
	psql -c "drop database if exists \"$(LOCAL_DB_NAME)\""
	psql -c "create database \"$(LOCAL_DB_NAME)\""
	make db-migrate

.PHONY: generate-sqlc
generate-sqlc:
	$(BINDIR)/sqlc generate
