Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple connections managed by migrations #590

Merged
merged 4 commits into from
Mar 11, 2025

Conversation

tobias-93
Copy link
Contributor

@tobias-93 tobias-93 commented Jan 28, 2025

References doctrine/migrations#1406, which fixes the filtering of the migrations table for the default connection but not for any other connections.
This PR applies the filter to each of the Doctrine connections.
Not sure what else is required in terms of tests/documentation etc.

@arderyp
Copy link

arderyp commented Jan 28, 2025

Is "my_custom_connection" on the example the name of a migration table? This example/naming confuses me

@tobias-93
Copy link
Contributor Author

Is "my_custom_connection" on the example the name of a migration table? This example/naming confuses me

No, it is the name of a connection (see https://symfony.com/doc/current/reference/configuration/doctrine.html#doctrine-dbal-configuration). The name of the migrations table (of which there is only one per database/connection) is configured in the storage (see https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html#configuration)

@arderyp
Copy link

arderyp commented Jan 29, 2025

No, it is the name of a connection

How then does this relate to or fix the issue of the default dropping of the migrations table (the issues you posted this PR to as a solution)

Forgive my confusion, I must be missing something

@tobias-93 tobias-93 force-pushed the fix-multiple-connections branch 2 times, most recently from a9ce3bd to 953d8c8 Compare February 11, 2025 19:24
@tobias-93
Copy link
Contributor Author

With the latest update, the configuration value is no longer needed. I have verified it and it works correctly for multiple connections now.

@tobias-93 tobias-93 force-pushed the fix-multiple-connections branch from 953d8c8 to 7569f07 Compare February 11, 2025 20:09
@tobias-93 tobias-93 requested a review from greg0ire February 11, 2025 20:36
Copy link
Member

@SenseException SenseException left a comment

Choose a reason for hiding this comment

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

This feature looks testable (tests/DependencyInjection/DoctrineMigrationsExtensionTest.php)

@tobias-93 tobias-93 force-pushed the fix-multiple-connections branch from 56ee74d to 1c6abc3 Compare February 18, 2025 20:30
@tobias-93 tobias-93 force-pushed the fix-multiple-connections branch from 1c6abc3 to 0d9e53d Compare February 18, 2025 20:40
@arderyp
Copy link

arderyp commented Feb 19, 2025

With the latest update, the configuration value is no longer needed. I have verified it and it works correctly for multiple connections now.

So... a return to the pre-break default behavior of assuming/expecting/ignoring a migration_versions table per connection? If not, would you mind explaining more?

@tobias-93
Copy link
Contributor Author

@arderyp indeed, the configured migrations table name is filtered in the migrations context. Pre-break this needed to be configured in the DBAL context if I'm not mistaken, which is now done automatically

@arderyp
Copy link

arderyp commented Feb 19, 2025

Thanks @tobias-93

I'm not entirely clear on your latest comment. Here is how I remember the series of events

Years ago I had to configure doctrine migrations to ignore my migrations table. Then eventually DM changed something such that the migrations table that was configured was ignored by default. Then, something broke, and required me to explicitly ignore the migrations tables again, despite them being explicitly configured (and thus eligible to discovering and ignoring).

Are you saying that this PR will make it so DM automatically detects configured migration tables and ignores them again, automatically... no need for explicitly filtering them out?

If so, that's great!

@tobias-93
Copy link
Contributor Author

tobias-93 commented Feb 19, 2025

@arderyp in fact it is already filtered for the default connection, so if you're just using one connection with migrations you can simply remove the filter and enjoy! This PR makes sure this auto-filter is also applied to any additional connection which is defined in the DBAL config.

Co-authored-by: Grégoire Paris <[email protected]>
@Pixelshaped
Copy link

Having multiple connections and entity managers, I get the DROP TABLE doctrine_migration_versions; on doctrine:migration:diff. Thanks for your PR, waiting for the release :)

@greg0ire greg0ire merged commit 5a6ac71 into doctrine:3.4.x Mar 11, 2025
15 checks passed
@greg0ire
Copy link
Member

Thanks @tobias-93 !

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.

5 participants