Repository navigation
Fix #360: Support named database migration sets with --db selection, a single configuration source for default, and separate migration history - #361
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Cross-database migration execution is operationally sensitive, and non-SQLite driver suites were not run.
Review effort: Balanced
Findings: None
What changed in this PR
Adds named database migration sets with --db selection while preserving the existing configuration as the default set.
Changes:
- Introduces per-database connections, migration sources, generation settings, and history.
- Extends all six migration commands with database selection and multi-set execution.
- Adds configuration wiring, documentation, and comprehensive SQLite/console tests.
| File | Description |
|---|---|
src/DatabaseSet.php |
Defines named-set configuration. |
src/DatabaseSetRegistry.php |
Builds commands for named sets. |
src/Command/DatabaseCommand.php |
Coordinates selection and iteration. |
src/Command/CreateCommand.php |
Supports selected-set generation. |
src/Command/DownCommand.php |
Supports selected-set rollback. |
src/Command/HistoryCommand.php |
Lists per-set history. |
src/Command/NewCommand.php |
Lists pending migrations per set. |
src/Command/RedoCommand.php |
Supports selected-set redo. |
src/Command/UpdateCommand.php |
Applies migrations per set. |
config/params.php |
Adds the databases parameter. |
config/di-console.php |
Registers the set registry. |
bin/yii-db-migration.php |
Documents standalone configuration. |
bin/yii-db-migration |
Wires sets into standalone commands. |
README.md |
Links database-set documentation. |
docs/guide/en/README.md |
Adds the guide entry. |
docs/guide/en/multiple-databases.md |
Documents behavior and configuration. |
docs/guide/en/usage-standalone.md |
Links standalone users to the guide. |
docs/guide/en/usage-with-symfony.md |
Links Symfony users to the guide. |
docs/guide/en/usage-with-yii-console.md |
Links Yii users to the guide. |
CHANGELOG.md |
Records the feature. |
tests/Migration/DatabaseSetRegistryTest.php |
Tests registry validation and order. |
tests/Migration/ConfigTest.php |
Tests Yii DI integration. |
tests/Migration/BinTest.php |
Tests standalone named-set execution. |
tests/Driver/Sqlite/DatabaseCommandsTest.php |
Covers command behavior and isolation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #361 +/- ##
============================================
+ Coverage 96.90% 97.21% +0.31%
- Complexity 311 347 +36
============================================
Files 20 25 +5
Lines 1000 1114 +114
============================================
+ Hits 969 1083 +114
Misses 31 31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
vjik
left a comment
There was a problem hiding this comment.
The registry and the commands depend on each other: DatabaseSetRegistry imports all six commands and DatabaseCommand to build per-set command instances, while the commands depend on the registry. It looks bad...
What if the registry didn't know about commands at all? For example, it could expose per-set services (a small internal context with Migrator, MigrationService, DownRunner and UpdateRunner built from a DatabaseSet), and the commands would use their constructor dependencies for default and ask the registry for the context of a named set. This removes the cycle and the command cloning while keeping existing constructor signatures and DI overrides of the default services intact.
--db selection, a single configuration source for default, and separate migration history
Applications with separate databases currently need to wire independent migration commands manually. Add named database sets and
--dbselection to all six commands, keeping execution, transactions, migration sources, and history on the selected connection.Configure
defaulteither through existing settings or entirely indatabases['default']. Named-set wiring does not require legacy connection or migration services. Standalone and Yii parameter configuration reject conflicting legacy options instead of silently overriding them. Without--db,up,new, andhistoryprocess default first, then additional sets in configuration order, stopping on errors.createuses default;downandredorequire an explicit database when multiple sets are configured. Listing commands succeed if any set has results and fail if all sets are empty; limits apply per set. With multiple sets,upandnewrequire--dbwhen using--pathor--namespace.Includes Yii Console and standalone configuration wiring, a Symfony configuration example with explicit registry wiring, a multiple-database guide, and a changelog entry. Existing command constructor calls and standalone configuration files remain supported.
Fixes #360.