Documentation
¶
Overview ¶
Package sqlmigrate is the shared forward-only SQL migration runner for Harbor's SQLite and Postgres persistence drivers. It is the single home of the migration contract that was previously copy-pasted per driver: the `NNNN_<slug>.sql` filename rule, the partial-apply precheck against `schema_migrations`, the per-migration transaction, and (Postgres) the FNV-64a advisory-key derivation that serialises concurrent boots.
Forward-only contract (unchanged from the per-driver runners): migrations are numbered monotonically; editing a merged migration is forbidden; future schema changes land as new files. A bad filename in the embed set is a build-time bug and is surfaced loudly, never skipped.
SQLite and Postgres keep deliberately distinct runners — they differ in the migrations-table DDL (`TIMESTAMP`/`CURRENT_TIMESTAMP` vs `TIMESTAMPTZ`/`NOW()`), in who records the applied version (the SQLite runner inserts it; the Postgres migration body inserts its own row), and in concurrency control (Postgres takes a session `pg_advisory_lock`, SQLite needs none). Each driver passes its own embedded `migrations/` FS and error prefix so wrapped errors read exactly as before.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunPostgres ¶
func RunPostgres(ctx context.Context, db *sql.DB, migrationsFS fs.FS, errPrefix, advisoryLockName string) error
RunPostgres applies any forward-only migrations in migrationsFS not yet recorded in `schema_migrations` to db, wrapping the run in a session-level `pg_advisory_lock` derived from advisoryLockName so concurrent New() calls across replicas don't race. errPrefix is the driver's error-wrap prefix (e.g. "postgres", "memory/postgres"). The migration body records its own schema_migrations row.
func RunSQLite ¶
RunSQLite applies any forward-only migrations in migrationsFS whose version is not already present in `schema_migrations` to db. errPrefix is the driver's error-wrap prefix (e.g. "state/sqlite"). Each migration runs inside a single transaction; the runner records the applied version with `INSERT OR IGNORE` so a partially-applied DB (DDL applied but the trailing INSERT lost) is still recoverable.
Types ¶
This section is empty.