Add the golib scaffold and the pg module #1
Reference in New Issue
Block a user
Delete Branch "benvin/initial-pg"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Every service reimplements the same Postgres plumbing; golib gives it one home and one set of tests.
How
pg.DSNFromEnv(prefix), consolidating the byte-identical DSN builders in encapi, artifactapi and forgebot:<PREFIX>DATABASE_URLandDATABASE_URLpass through verbatim, then prefixedDB*vars, then libpqPG*vars, then defaults, resolved per field. User and database name have no default and error instead. User and password are percent-escaped, so a password containing@or/no longer truncates the host.pg.New(ctx, dsn, log), which pings before returning so an unreachable server fails at startup rather than on the first query, andpg.NewMigrated, which migrates before handing the pool back.pg.Migrate(ctx, pool, fsys, pg.MigrateOptions{LockName, Logger}), preserving arrproxy's runner semantics exactly — advisory lock on a dedicated pooled connection, one transaction per file covering both the SQL and itsschema_migrationsrow, connection discarded when the unlock does not land — and generalising the hardcoded lock key to FNV-1a/64 ofLockNameand the embedded set to anfs.FS.pg.LockKeyexposes the derivation so a service can assert it matches its old hardcoded key before switching.pg/pgtest, unifying the encapi and artifactapi testcontainers helpers behindStartPostgres/MustStartPostgresonpostgres:17-alpine, with the Ryuk-disable workaround andSkipIfShortso container-backed tests self-skip on the Docker-less Kubernetes runners.pgMigratorruns against asessioninterface, so the exact SQL, arguments and transaction ordering are unit-tested. The migration runner keeps arrproxy's fake-DB suite (ordering, lock exclusion, concurrent starters, mid-set failure, unlock failure). Container-backed integration tests cover the real path behind-short.buildcompiles every package,testruns the unit suite,test-allincludes the integration tests, andcovergates on 90% statement coverage over the shipped packages. The gate runs-short, so it clears without a database;pg/pgtestis excluded as test scaffolding. Measured coverage is 93.2%.test,pre-commitandbuildpull-request pipelines ongolib-ci, mirroring mediamark's pre-commit lanes (gofmt/vet, golangci-lint,uvx pre-commit), plus the encapi pre-commit config. Nodocker.yaml: golib ships no image.go get git.unkin.net/unkin/golib@vX.Y.Zconsumption, and the 90% bar.make build,make cover(93.2%),golangci-lint,go vet,gofmtanduvx pre-commit run --all-filesall pass locally, as do the container-backed integration tests against real Postgres.