23 Commits

Author SHA1 Message Date
3e51c7b67a
fix(sqlmigrate): make n=0 an error in Up/Down, use -1 for "all"
Passing 0 to Up() or Down() is an easy mistake — it silently means
"all" which could be destructive. Now n=0 returns ErrInvalidN.
Convention: n > 0 for a specific count, n < 0 (typically -1) for all.
2026-04-08 15:51:25 -06:00
3547b7e409
ref(database/sqlmigrate): extract migration library with shmigrate backend
Factor the inline migration logic from cmd/sql-migrate into reusable
packages: database/sqlmigrate (core types, matching, file collection)
and database/sqlmigrate/shmigrate (shell script generation backend).

No behavior changes — the CLI produces identical output. The shmigrate
package implements the sqlmigrate.Migrator interface so other backends
(pgmigrate, mymigrate, etc.) can follow the same pattern.
2026-04-08 15:37:03 -06:00
c4964a5b65
chore(sql-migrate): remove dead subcmd != "create" checks in status/list cases
Go switch cases don't fall through, so subcmd can never be "create"
when we're inside the "status" or "list" case.
2026-04-08 15:21:04 -06:00
da7f45438c
doc(sql-migrate): add PGOPTIONS multi-tenant schema docs to help text
Document how to use PGOPTIONS="-c search_path=..." for multi-tenant
PostgreSQL migrations. Each schema gets its own _migrations table,
so tenants are migrated independently.
2026-04-08 15:06:41 -06:00
2080ae223d
fix(sql-migrate): reject explicit 'up 0' and 'down 0' as invalid
An explicit 0 argument should error, not silently run all pending (up)
or get handled as a special case (down). Change the guard from < 0 to
< 1 in both subcommands so '0' is treated as invalid input.
2026-04-08 14:57:55 -06:00
03d81a2b76
fix(sql-migrate): reject explicit 'up 0' as invalid
An explicit 0 argument to 'up' should error (like 'down 0' already
does), not silently run all pending migrations. Change the guard
from < 0 to < 1 to match 'down' behavior.
2026-04-08 14:41:09 -06:00
40fa1e876c
fix(sql-migrate): add missing --tuples-only to psql examples in help text
The psql command constant uses -A -t (--no-align --tuples-only) but
the help text and code comments only showed --no-align. Without
--tuples-only, psql prints column headers into migrations.log,
corrupting it.
2026-04-08 13:45:11 -06:00
404079f154
fix(sql-migrate): use goreleaser ldflags for version info
Replace hardcoded version const with var block populated by goreleaser
ldflags (version, commit, date). Add printVersion() matching the pattern
used by sibling commands (tcpfwd, smsapid, auth-proxy). Fix date var
shadowing in main() by renaming local to today.
2026-04-08 02:57:53 -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
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
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