Skip to content

Fix #360: Support named database migration sets with --db selection, a single configuration source for default, and separate migration history - #361

Merged
samdark merged 17 commits into
masterfrom
feature/named-migration-databases
Oct 2, 2026
Merged

samdark merged 17 commits into
masterfrom
feature/named-migration-databases

Conversation

@samdark

@samdark samdark commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Applications with separate databases currently need to wire independent migration commands manually. Add named database sets and --db selection to all six commands, keeping execution, transactions, migration sources, and history on the selected connection.

Configure default either through existing settings or entirely in databases['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, and history process default first, then additional sets in configuration order, stopping on errors. create uses default; down and redo require 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, up and new require --db when using --path or --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.

Q A
Is bugfix? ❌
New feature? ✔️
Breaks BC? ❌

Fixes #360.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 10:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.21%. Comparing base (4a9eb5e) to head (2432d7d).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vjik vjik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CHANGELOG.md Outdated
Comment thread src/Command/NewCommand.php Outdated
Comment thread src/Command/HistoryCommand.php Outdated
@samdark
samdark requested a review from vjik September 30, 2026 21:58
Comment thread docs/guide/en/usage-standalone.md Outdated
@samdark samdark changed the title Add named database migration sets and --db selection Fix #360: Support named database migration sets with --db selection, a single configuration source for default, and separate migration history Oct 2, 2026
@samdark
samdark merged commit 3c06394 into master Oct 2, 2026
59 checks passed
@samdark
samdark deleted the feature/named-migration-databases branch October 2, 2026 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lack of a simple approach for "Database per Service"

4 participants