Adding local postgres setup

main
Drew Bednar 2 weeks ago
parent 5e33a8a44c
commit 47b2e1f6d2

4
.gitignore vendored

@ -21,4 +21,6 @@
# Go workspace file
go.work
tmp/
tmp/
.pg_data/

@ -0,0 +1,5 @@
export PG_DATABASE=pulley
export PG_USER=pulley
export PG_PASSWD=passwd
export PG_URI=postgres://pulley:passwd@localhost:5434/pulley

@ -40,24 +40,21 @@ serve:
go run ./cmd/api/...
.PHONY: serve
# SQLite Commands
sql-cli:
sqlite3 $(SQL_DATABASE) -cmd ".headers on" -cmd ".mode box" -cmd ".tables"
.PHONY: sql-cli
start-local:
mkdir -p ./.pg_data && \
chown $$(id -u):$$(id -g) ./.pg_data && \
UID=$$(id -u) GID=$$(id -g) docker compose up -d
.PHONY: start-local
init-db: run-migrate
sqlite3 $(SQL_DATABASE) "PRAGMA journal_mode = WAL; PRAGMA synchronous = NORMAL;"
.PHONY: init-db
run-migrate:
migrate -database sqlite3://$(SQL_DATABASE) -path ./migrations up
.PHONY: run-migrate
stop-local:
docker compose down
.PHONY: stop-local
# Checks system dependencies needed to run the local dev environment
check-system-deps:
@echo "Checking system dependencies..."
@command -v air > /dev/null || (echo "Missing air command. go install github.com/air-verse/air@latest"; exit 1)
@command -v sqlite3 > /dev/null || (echo "Missing sqlite3 command. brew install sqlite"; exit 1)
@command -v psql > /dev/null || (echo "Missing psql command. brew install libpq"; exit 1)
@command -v migrate > /dev/null || (echo "Missing migrate command. go install -tags 'sqlite3' github.com/golang-migrate/migrate/v4/cmd/migrate@latest"; exit 1)
@echo "System dependencies fulfilled 👍"
.PHONY: check-system-deps
@ -65,4 +62,4 @@ check-system-deps:
local-certs:
cd ./tls && go run /usr/local/go/src/crypto/tls/generate_cert.go --rsa-bits=2048 --host=localhost
.PHONY: local-certs
.PHONY: local-certs

@ -0,0 +1,14 @@
services:
postgres:
image: postgres:16
container_name: pulleydb
environment:
POSTGRES_USER: pulley
POSTGRES_PASSWORD: passwd
POSTGRES_DB: pulley
ports:
- "5434:5432" # Host:Container
volumes:
- ./.pg_data:/var/lib/postgresql/data
user: "${UID}:${GID}"
Loading…
Cancel
Save