Conversation
Add getTargetConnections() to DatabaseChange, allowing migrations and seeders to declare which named connections they apply to. Empty array (default) means all connections, preserving backward compatibility. SchemaRunner filters changes by connection name at apply-time, consistent with the existing getEnvironments() pattern. Skipped changes are recorded with reason 'Connection mismatch'. Filtering is applied in: apply(), applyOne(), getPendingChanges(), skipAll(), skipNext(), and skipUpTo(). Closes #149 Ref: WebFiori/framework#326
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #152 +/- ##
============================================
+ Coverage 75.06% 75.08% +0.01%
- Complexity 2174 2185 +11
============================================
Files 54 54
Lines 5403 5427 +24
============================================
+ Hits 4056 4075 +19
- Misses 1347 1352 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
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.



Summary
Add the ability to restrict migrations and seeders to specific named database connections, enabling multi-database architectures where certain schema changes should only apply to specific databases.
Motivation
In multi-tenant applications or systems with multiple databases (e.g., one for user data, another for reporting), not all migrations should apply to every database. Currently, running migrations applies all discovered changes regardless of which database they belong to.
This feature follows the same pattern as the existing
getEnvironments()method for environment-based filtering, extending it to connection-based filtering.Changes
DatabaseChange::getTargetConnections(): array— declares which connections a change applies to. Empty array (default) means all connections.SchemaRunner::shouldRunForConnection()— filters changes by connection name at apply-timeapply(),applyOne(),getPendingChanges(),skipAll(),skipNext(),skipUpTo()Connection mismatchinDatabaseChangeResultCreateReportsTableMigration.php) demonstrating the featureHow to Test / Verify
11 tests pass covering: default behavior, matching/mismatched connections, multiple targets, mixed targeting, seeder filtering,
getPendingChanges, andapplyOne.Full schema suite (162 tests) passes with no regressions.
Breaking Changes and Migration Steps
None. Default
getTargetConnections()returns[](all connections), so existing migrations are unaffected.Checklist
Related issues
Closes #149
Follow-up for CLI integration: WebFiori/framework#326