Adopt golib/pg for migrations and pool construction #6
Reference in New Issue
Block a user
Delete Branch "benvin/adopt-golib-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
encapi applied its schema as one cumulative
IF NOT EXISTSblob re-executedinline on every start. It grows forever, records nothing about what has run, and
cannot express a change that is not a fresh
CREATE.git.unkin.net/unkin/golibnow owns that mechanism (versioned files,
schema_migrations, advisory lock), soencapi should keep the SQL and drop the runner.
How
migrations/0001_init.sql, embedded viamigrations.FS. It staysIF NOT EXISTS-guarded, so the first start againstthe live database re-runs it as a no-op and only lands the tracking row.
pg.NewMigratedunder the lock nameencapi-migrations,and delete the inline
migrate().database.Newnow takes a context and alogger;
main.gopasses the signal context, so a start queued on themigration lock still dies on SIGTERM.
pg.DSN. The env var contract is unchanged —DBHOST/DBPORT/DBUSER/DBPASS/DBNAME/DBSSLare still resolved byinternal/config, notpg.DSNFromEnv, because encapi defaultsDBUSERandDBNAMEtoencapiwhereDSNFromEnvtreats both as required.migrations/, everyCREATEmust beidempotent, the derived advisory key is pinned to its computed value, and a
container test proves the adoption path over a database that predates
schema_migrations.make test-shortnow covers./migrations/....GOPRIVATE=git.unkin.netfor the first cross-repo Go dependency:Makefile export, Dockerfile
ENV, woodpecker Go steps, README note.Full suite green with Postgres via testcontainers; gofmt/vet/pre-commit clean.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.