feat: add ledger-backed database migrations and migrate-* CLI - #286
Open
Ibochkarev wants to merge 4 commits into
Open
feat: add ledger-backed database migrations and migrate-* CLI#286Ibochkarev wants to merge 4 commits into
Ibochkarev wants to merge 4 commits into
Conversation
MigrationConsoleTest loads Application::loadCommands(), which autoloads ParseSchema/WriteSchema. Without `: int` PHP fatals under symfony/console ^6|^7.
Ibochkarev
marked this pull request as ready for review
August 14, 2026 12:58
Tighten consumer docs (identity, transactions, locks) and cover UNIQUE version inserts plus ledger write after up() clears the connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
xPDO has schema codegen (
parse-schema/write-schema) and Transport packaging, but no ordered, ledger-backed way to apply and reverse database changes across environments. PR #143 (2018–2023) sketched this and closed unmerged: no tests, mysql-centric ledger maps, install-gated commands, branch gone. This PR is a new implementation for current3.x(PHP ≥8.1; mysql/pgsql/sqlite like existing CI), not a rebase of that diff.What this PR adds
xPDO\Migrations\with publicMigrator,Migration,MigrationContext,MigrationConfig, plusMigratorResultDTOs.xpdo_migrations):version(UNIQUE),batch,applied_at. Row only after successfulup().bin/xpdo:migrate-create,migrate-status,migrate,migrate-rollback(always registered; hyphen names likeparse-schema).pgsqltoCommand::$platforms.transaction_policy=non_transactional(MySQL DDL often implicit-commits; stubs andcli.mdsay so). Policytransactionalwraps each migration’sup/down+ ledger write.--stepon migrate/rollback.test/xPDO/Test/Migrations/. CLI docs:docs/migrations/cli.md.Out of scope (explicit): schema diff, seeds,
migrate-fresh, sqlsrv CI gate, checksums.Compatibility
pgsqlon$platforms, and: inton existingParseSchema/WriteSchemaexecute()(Symfony Console 6).Maintainer value
bin/xpdoas schema tools.upis not recorded; later pending stop. You can roll back the last (including partial) batch.@internal.Verified
--filter MigrationSkips on non-sqlite: sqlite-only flock process test; CLI tests skipped when
xpdo_driveris not sqlite (harness uses a sqlite DSN).Example usage
PHP:
new Migrator($xpdo, MigrationConfig::fromArray([...]))thencreate()/status()/migrate()/rollback().Reviewer notes
Migrator,Migration,MigrationContext,MigrationConfig,MigratorResult. Rest is@internal.YYYYMMDDHHMMSS_Description; ledgerversionUNIQUE.cli.md.Test plan
vendor/bin/phpunit -c ./test/sqlite.phpunit.xml --filter Migrationvendor/bin/phpunit -c ./test/mysql.phpunit.xml --filter Migrationvendor/bin/phpunit -c ./test/pgsql.phpunit.xml --filter Migrationphp bin/xpdo listshows the four migrate-* commands