Adds the melange generate migration command for external migration framework integration, introduces two-phase skip detection to the built-in migrator, and includes new unit tests and documentation improvements.
Note
No breaking changes from v0.7.3. The built-in migrator automatically adds a function_checksums column to melange_migrations on the next melange migrate run.
Highlights
melange generate migration — External Migration Framework Support
Users with existing migration systems (golang-migrate, sqlx, Flyway, etc.) can now generate versioned UP/DOWN SQL files instead of running melange migrate directly. Inspired by River Queue's migrate-get command pattern.
# Full migration (first time or periodic snapshot)
melange generate migration \
--schema schemas/schema.fga \
--output db/migrations
# Diff migration against main branch (ideal for PRs)
melange generate migration \
--schema schemas/schema.fga \
--output db/migrations \
--git-ref mainThree comparison modes control which functions appear in the migration:
| Mode | Flag | Use Case |
|---|---|---|
| Full (default) | (none) | First migration or periodic full snapshot |
| Database | --db <url>
| Most precise — reads melange_migrations from a live database
|
| Git | --git-ref <ref>
| No database needed — compares against a branch, tag, or commit |
| File | --previous-schema <path>
| Compares against a local backup of the last-deployed schema |
Function-level change detection uses SHA-256 checksums to include only changed functions in diff migrations. Dispatcher functions are always regenerated. Orphaned functions from removed relations receive DROP FUNCTION IF EXISTS statements.
Two-Phase Skip Detection in the Built-in Migrator
melange migrate now uses two-phase skip detection to avoid unnecessary database writes:
- Phase 1 (fast path): If both the schema checksum and melange version match the last migration, skip entirely — no SQL generation needed.
- Phase 2 (smart apply): If the schema or version changed, generate SQL and compare function checksums. If every function is identical and no orphans exist, skip re-applying and only record the new migration state.
This makes melange version upgrades efficient when the generated SQL hasn't actually changed.
Improvements
- Simplified config schema — redundant per-subcommand
schemafields removed in favour of a single top-levelschemafield - Added Migrations concept guide covering both the built-in migrator and external framework integration
- Documented the
melange generate migrationcommand in the CLI reference - Fixed all broken internal links across the documentation site
Testing & Maintenance
- Added unit tests for
pkg/migratorandpkg/clientgen - Added migration system integration tests covering two-phase skip detection
- Upgraded
google.golang.org/grpcfrom v1.78.0 to v1.79.3 - Enhanced README with Matrix chat link and contribution details
Install / Upgrade
# CLI
brew install pthm/melange/melange
# Go runtime
go get github.com/pthm/melange/melange@v0.7.4
# TypeScript runtime
npm install @pthm/melange
# Apply migrations
melange migrateFull blog post: https://melange.pthm.dev/blog/v0.7.4/