diff --git a/.gitignore b/.gitignore index 26ef082..120a0ee 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ # Go workspace file go.work -tmp/ \ No newline at end of file +tmp/ + +.pg_data/ diff --git a/.local.profile b/.local.profile new file mode 100644 index 0000000..dc263d6 --- /dev/null +++ b/.local.profile @@ -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 + diff --git a/Makefile b/Makefile index 1a2841f..775c848 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file +.PHONY: local-certs diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..b861b0a --- /dev/null +++ b/docker-compose.yaml @@ -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}" +