[hw-4] add postgres db

This commit is contained in:
Никита Шубин
2025-06-26 12:08:46 +00:00
parent 3ebaad5558
commit 77ed9fcf85
46 changed files with 1582 additions and 369 deletions

View File

@@ -1,11 +1,40 @@
BINDIR=${CURDIR}/bin
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:
echo "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