Files
3ybactuk-marketplace-go-ser…/comments/Makefile
2025-07-28 14:58:08 +03:00

43 lines
1.2 KiB
Makefile

BINDIR=${CURDIR}/../bin
PACKAGE=route256/comments
MIGRATIONS_FOLDER := ./db/migrations/
LOCAL_DB_NAME := route256
LOCAL_DB_DSN := postgresql://user:password@localhost:5433/route256?sslmode=disable
PROD_USER := comments-user
PROD_PASS := comments-password
PROD_DB := postgres-comments-shard
PROD_MIGRATIONS := ./comments/db/migrations/
build: bindir
echo "build comments"
go build -o ${BINDIR}/comments cmd/server/main.go
bindir:
mkdir -p ${BINDIR}
# Used for CI
run-migrations:
$(GOOSE) -dir $(PROD_MIGRATIONS) postgres "postgresql://$(PROD_USER)-1:$(PROD_PASS)-1@$(PROD_DB)-1:5432/comments_db?sslmode=disable" up
$(GOOSE) -dir $(PROD_MIGRATIONS) postgres "postgresql://$(PROD_USER)-2:$(PROD_PASS)-2@$(PROD_DB)-2:5432/comments_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