M1/#291: wire Postgres migrations + pgxpool #4

Merged
bvandeusen merged 262 commits from dev into main 2026-04-18 21:38:10 -04:00
bvandeusen commented 2026-04-18 21:35:45 -04:00 (Migrated from git.fabledsword.com)

Summary

First M1 step — replace the stubbed internal/db package with a real Postgres layer:

  • internal/db/db.go: Open() returns a pgxpool.Pool; Migrate() runs embedded migrations via golang-migrate/v4 with the pgx/v5 driver (registered scheme pgx5).
  • internal/db/migrations/0001_init.{up,down}.sql: placeholder migration to establish the runner. Real schema (artists/albums/tracks/users) lands in 0002 (task #292).
  • cmd/minstrel/main.go: run db.Migrate then db.Open on startup; defer pool.Close().
  • go.mod / go.sum: add github.com/jackc/pgx/v5 v5.7.4, github.com/golang-migrate/migrate/v4 v4.18.2. Pinned to versions that still support the go 1.23 toolchain (newer releases require 1.24/1.25).
  • docker-compose.yml: add minstrel service that depends on healthy postgres and wires SMARTMUSIC_DATABASE_URL.
  • .env.example: document SMARTMUSIC_* overrides + the opt-in MINSTREL_TEST_DATABASE_URL.
  • internal/db/db_test.go: env-var-gated real-Postgres test (idempotent Migrate + schema_migrations count). Skipped in -short mode (CI) and when the env var is unset.

Local verification

  • go vet ./... && gofmt -l . clean.
  • go test -short -race ./... green (CI-equivalent).
  • With docker run ... postgres:16-alpine: go test ./... -run TestMigrate green (both migrations applied idempotently).
  • Smoke test: go run ./cmd/minstrel against the local pg → log migrations applied version=1 dirty=falsecurl /healthz{"status":"ok"}.
  • CI runner image parity: docker run ... git.fabledsword.com/bvandeusen/runner-base:go-ci bash -c 'golangci-lint run ./... && go test -short -race ./...' green.

Test plan

  • Forgejo Actions test.yml passes on this PR
  • Merge → release.yml publishes updated :main image
  • Server starts cleanly against compose postgres (already verified locally)

Tracks Fable task #291 under milestone 26 (M1 Subsonic baseline).

## Summary First M1 step — replace the stubbed `internal/db` package with a real Postgres layer: - `internal/db/db.go`: `Open()` returns a `pgxpool.Pool`; `Migrate()` runs embedded migrations via `golang-migrate/v4` with the `pgx/v5` driver (registered scheme `pgx5`). - `internal/db/migrations/0001_init.{up,down}.sql`: placeholder migration to establish the runner. Real schema (artists/albums/tracks/users) lands in 0002 (task #292). - `cmd/minstrel/main.go`: run `db.Migrate` then `db.Open` on startup; defer `pool.Close()`. - `go.mod` / `go.sum`: add `github.com/jackc/pgx/v5 v5.7.4`, `github.com/golang-migrate/migrate/v4 v4.18.2`. Pinned to versions that still support the `go 1.23` toolchain (newer releases require 1.24/1.25). - `docker-compose.yml`: add `minstrel` service that depends on healthy `postgres` and wires `SMARTMUSIC_DATABASE_URL`. - `.env.example`: document `SMARTMUSIC_*` overrides + the opt-in `MINSTREL_TEST_DATABASE_URL`. - `internal/db/db_test.go`: env-var-gated real-Postgres test (idempotent Migrate + `schema_migrations` count). Skipped in `-short` mode (CI) and when the env var is unset. ## Local verification - `go vet ./... && gofmt -l .` clean. - `go test -short -race ./...` green (CI-equivalent). - With `docker run ... postgres:16-alpine`: `go test ./... -run TestMigrate` green (both migrations applied idempotently). - Smoke test: `go run ./cmd/minstrel` against the local pg → log `migrations applied version=1 dirty=false` → `curl /healthz` → `{"status":"ok"}`. - CI runner image parity: `docker run ... git.fabledsword.com/bvandeusen/runner-base:go-ci bash -c 'golangci-lint run ./... && go test -short -race ./...'` green. ## Test plan - [ ] Forgejo Actions `test.yml` passes on this PR - [ ] Merge → `release.yml` publishes updated `:main` image - [ ] Server starts cleanly against compose postgres (already verified locally) Tracks Fable task #291 under milestone 26 (M1 Subsonic baseline).
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bvandeusen/minstrel#4