21 Commits

Author SHA1 Message Date
3461dcbc7d
fix(sqlmigrate): Down n=0 means rollback all, add tests and docs
- Change Down(n<=0) to mean "rollback all" (matching Up semantics).
  CLIs now explicitly pass 1 when no count is given.
- Add 22 tests for Collect, NamesOnly, Up, Down, and GetStatus
  using mock Migrator and fstest.MapFS.
- Fix shmigrate.Applied to stream from file instead of ReadFile
  double-wrap; add optional FS field for embed.FS support.
- Update package doc to list all 5 backends.
- Add minimal README linking to pkg.go.dev.
2026-04-06 00:40:12 -06:00
de227bcaaf
feat(sql-migrate/examples): add pg-todos embedded migration runner
Example CLI todo app demonstrating sqlmigrate + pgmigrate for running
migrations directly via pgx/v5 instead of shelling out to psql. Uses
embed.FS for migration files, auto-migrates on startup, and includes
full CRUD for todos and folders with sqlc-ready query files.
2026-04-06 00:40:11 -06:00
a86d901d64
feat(database/sqlmigrate): add migration library with multi-backend support
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.
2026-04-06 00:40:11 -06:00
075cc7b286
fix(sql-migrate): add missing ! to shebang in generated scripts
Generated shell scripts had `#/bin/sh` instead of `#!/bin/sh`,
meaning the shebang was treated as a comment rather than an
interpreter directive.
2026-04-06 00:39:36 -06:00
4a9c331ef9
Fix INSERT INTO _migrations ordering in create and fixup
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
2026-03-30 15:58:21 -06:00
87b666ffd3
chore(cmd/sql-migrate): add .goreleaser.yaml 2026-03-28 17:16:40 -06:00
690cf90d67
chore(cmd/sql-migrate): add .goreleaser.yaml 2026-03-23 11:43:08 -06:00
1f61095873
feat(sql-migrate): add sync subcommand
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
2026-03-23 11:42:23 -06:00
b50696f64d feat(sql-migrate): skip +-prefixed files in migrations directory (refs #68) 2026-03-23 11:39:49 -06:00
3487702bf7 fix(sql-migrate): use 6-digit zero-padded number in init migration filename (refs #68) 2026-03-23 11:39:49 -06:00
4895012d67 fix(sql-migrate): use portable SQL in _migrations table (closes #37) 2026-03-23 11:39:49 -06:00
21ea2d0613
chore(cmd/sql-migrate): bump v2.0.3 2026-01-31 21:22:42 -07:00
b6ffacd0a6
fix(cmd/sql-migrate): spell 'postgres' correctly 2026-01-31 21:21:53 -07:00
e7282c58f3
chore(cmd/sql-migrate): add explicit default for sqlCommand switch 2026-01-31 21:21:53 -07:00
dd4148b88e
chore(cmd/sql-migrate): make file path ormatting consistent for all 'found ./path/to/x' outtput 2026-01-31 21:21:53 -07:00
1ec145b3eb
ref(cmd/sql-migrate/v2): make INSERTs sortable, output cleanup 2026-01-31 01:18:58 -07:00
10236de205
feat(cmd/sql-migrate/v2): bump go.mod to v2 2026-01-31 00:20:07 -07:00
65f866970e
feat(cmd/sql-migrate/v2): store migrations in db, nix batches 2026-01-31 00:10:06 -07:00
fe6300dacc
chore(cmd/sql-migrate): bump to version 1.0.2 2026-01-13 00:30:48 -07:00
eee1a95f52
ref(cmd/sql-migrate): add package, docs, minor flag parse change 2026-01-13 00:30:08 -07:00
f034cf0529
feat(cmd/sql-migrate): can write up and down migrations 2026-01-13 00:29:55 -07:00