Extract a database-agnostic migration interface (Migrator) with Collect,
Up, Down, and GetStatus orchestration. Each backend is its own Go module
to avoid dependency bloat:
- sqlmigrate: core interface, types, sentinel errors, file collection
- pgmigrate: PostgreSQL via pgx/v5
- mymigrate: MySQL/MariaDB via go-sql-driver/mysql
- litemigrate: SQLite via database/sql (caller imports driver)
- msmigrate: SQL Server via go-mssqldb
- shmigrate: shell script generation (file-path commands, not heredocs)
Integrates shmigrate into the existing cmd/sql-migrate CLI, replacing
its bespoke up/down/status logic with sqlmigrate orchestration.
The create subcommand generated .up.sql files with INSERT INTO
_migrations as the FIRST statement, before the actual DDL. If the
DDL fails, the migration is incorrectly marked as applied. Move the
INSERT to be the LAST statement, matching how .down.sql already puts
DELETE FROM _migrations last.
Also fix the automatic fixup logic to append (not prepend) missing
INSERT statements to existing .up.sql files.
Fixes#86
Adds `sql-migrate sync` which outputs a shell script that refreshes
the local migrations.log from the DB by running _migrations.sql.
Uses `|| true` so a fresh DB with no _migrations table yields an
empty log (all migrations pending) rather than an error.
Usage:
sql-migrate -d ./db/migrations sync | sh
sql-migrate -d ./db/migrations up | sh