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

Make column and index renaming configurable #6300

Merged
merged 12 commits into from
Oct 11, 2024

Conversation

ausi
Copy link
Contributor

@ausi ausi commented Feb 6, 2024

Q A
Type improvement
Fixed issues #6299

Summary

Makes column and index rename detection of the Comparator configurable, as suggested in #6299 (comment)

@ausi ausi force-pushed the feature/rename-columns-configurable branch from b663bfe to d0c8602 Compare March 11, 2024 13:12
Copy link

There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days.
If you want to continue working on it, please leave a comment.

@github-actions github-actions bot added the Stale label Jun 10, 2024
@ausi
Copy link
Contributor Author

ausi commented Jun 10, 2024

I adressed all review comments.

Adressing this issue is quite important for us in order to get compatible with Doctrine 4.

@github-actions github-actions bot removed the Stale label Jun 11, 2024
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

I think this lacks documentation, and I'm curious to see what a real-world usage would look like, since "The comparator can be only instantiated by a schema manager" (so, at runtime, rather than at DIC compilation time).

src/Schema/ComparatorConfig.php Outdated Show resolved Hide resolved
@ausi
Copy link
Contributor Author

ausi commented Jun 21, 2024

I think this lacks documentation,

Should I add a section for createComparator() to docs/en/reference/schema-manager.rst ?
Or should it be a new page about the Comparator itself?

and I'm curious to see what a real-world usage would look like, since "The comparator can be only instantiated by a schema manager" (so, at runtime, rather than at DIC compilation time).

We would use it here: https://github.com/contao/contao/blob/aa54c3df007e4b01b73e08036e35c054a7d1fd84/core-bundle/src/Migration/CommandCompiler.php#L61-L66 like this:

$comparator = $schemaManager->createComparator();
$config = new ComparatorConfig();
$config->setDetectRenamedColumns(false);
$config->setDetectRenamedIndexes(false);
$comparator->setConfig($config);
$diffCommands = $comparator
    ->compareSchemas($fromSchema, $toSchema)
    ->toSql($this->connection->getDatabasePlatform())
;

Are you happy with the setConfig() approach? I think I’d prefer a third parameter to the methods compareTables and compareSchemas instead, see #6300 (comment)

@greg0ire
Copy link
Member

I would drop setConfig, and add a new argument to createComparator, so that the config can be readonly. Having it mutable doesn't feel great.

@ausi
Copy link
Contributor Author

ausi commented Jun 21, 2024

Should I make the Config object itself also immutable?

@greg0ire
Copy link
Member

I think everything should be made immutable by default, yes. If people need to mutate anything, they will send a PR explaining their use case, making it mutable won't be a breaking change.

@greg0ire
Copy link
Member

Should I add a section for createComparator() to docs/en/reference/schema-manager.rst ?

A section feels enough

@ausi
Copy link
Contributor Author

ausi commented Jun 21, 2024

I think this lacks documentation

Done in e117bbb

@ausi ausi force-pushed the feature/rename-columns-configurable branch from dd9bc52 to b4195ae Compare June 24, 2024 18:34
@ausi
Copy link
Contributor Author

ausi commented Jun 24, 2024

Failing CI seems to be unrelated.

greg0ire
greg0ire previously approved these changes Jun 24, 2024
# Conflicts:
#	src/Schema/Comparator.php
@ausi
Copy link
Contributor Author

ausi commented Aug 15, 2024

As this didn’t make it into the 4.1.0 release, should I change the base branch to 4.2.x?

@derrabus derrabus changed the base branch from 4.1.x to 4.2.x August 15, 2024 08:34
@uncaught
Copy link

uncaught commented Sep 6, 2024

This looks quite similar to what I've just done in #6521 - I've injected the Configuration where you inject this new config class of yours.

However, I'm curious as to how I would configure this at the end-user-level? The doctrine-bundle configures the Configuration, so it would be easy enough to add new options there. But how will this work on your class?

In my symfony project I see several places outside the dbal that call createComparator(): doctrine/migrations, symfony/doctrine-messenger, doctrine/orm. Do we have to configure all those places individually, add PRs there? The config should surely be the same across all of them.

I'm fine with having a dedicated config sub-class for the comparator, but would it not make sense to have it also as property on the Configuration, and then inject it from there, rather via an argument of createComparator?

@ausi
Copy link
Contributor Author

ausi commented Oct 10, 2024

@derrabus should I update this PR to also use Doctrine\DBAL\Configuration instead of introducing the new Doctrine\DBAL\Schema\ComparatorConfig?
Or should I nest the ComparatorConfig inside the Configuration object and pass that to the comparator?
Or should this PR be kept as it is now?

@derrabus
Copy link
Member

I think that it makes sense to configure this behavior when I actually want to compare stuff. Relying on global configuration for that matter sounds brittle to me. So, your new object is fine. The only thing that I would change is that passing a configuration to the comparator constructors should remain optional. I know that all the constructors are flagged as internal technically, but I don't believe that we have to break existing constructor calls for this change.

@derrabus derrabus changed the base branch from 4.2.x to 4.3.x October 10, 2024 13:10
@derrabus derrabus dismissed stale reviews from SenseException and greg0ire October 10, 2024 13:10

The base branch was changed.

@derrabus derrabus modified the milestones: 4.2.0, 4.3.0 Oct 10, 2024
@ausi
Copy link
Contributor Author

ausi commented Oct 10, 2024

…passing a configuration to the comparator constructors should remain optional…

Done in 4751bc9

It would be great if we could get this merged into the next version as this issue currently makes it impossible for us to be compatible with dbal version 4.

@uncaught
Copy link

uncaught commented Oct 11, 2024

I think that it makes sense to configure this behavior when I actually want to compare stuff.

So we'll need more PRs then for all the rest to implement support for this, right?

That means we need at least 3 new configurations like:

doctrine:
    dbal:
        compare_index_names: true # for ***SchemaManager::createComparator
    orm:
        compare_index_names: true # for SchemaTool::getUpdateSchemaSql

doctrine_migrations:
    compare_index_names: true # for DiffGenerator::generate

And fingers crossed they stay in sync.

@derrabus
Copy link
Member

That means we need at least 3 new configurations like:

Not sure what you're getting at an how this is relevant for this PR.

@uncaught
Copy link

If the comparator config needs to be provided to the createComparator method, then all these external libraries need to be updated, too, because they all call createComparator and you probably want them all to use the same config.

If this dbal provided a way to set this config somehow, before one would call createComparator, integration would be easier.

@derrabus
Copy link
Member

If the comparator config needs to be provided to the createComparator method

Which is not the case. You can do that, you don't need to if you're happy with the defaults.

you probably want them all to use the same config.

No, why?

@uncaught
Copy link

uncaught commented Oct 11, 2024

Ok, sorry, I thought this would be a fix for the indexes breaking because the migrations don't track index names at the moment.

A migration diff generated on db1 is not guaranteed to run on db2 if db2 was created later than db1 with the schema tools and the generated index names don't match anymore.

So I thought you would always want to have index name comparison enabled across the entire db suite (dbal/orm/migrations) or not at all.

I'll just stop complaining now - seems I cannot convince you ;)

@ausi
Copy link
Contributor Author

ausi commented Oct 11, 2024

I thought this would be a fix for the indexes breaking because the migrations don't track index names at the moment.

This pull request is about making the current behavior of detecting renames of columns and indexes optional by making it configurable. The fix you are talking about sounds like your own pull request here: #6521 ?

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Another small nit and I think I'm OK. Please squash commits that should not appear in the history such as the one to fix this nit.

docs/en/reference/schema-manager.rst Outdated Show resolved Hide resolved
@ausi ausi force-pushed the feature/rename-columns-configurable branch from 23f3119 to 92356cf Compare October 11, 2024 16:38
@ausi
Copy link
Contributor Author

ausi commented Oct 11, 2024

Please squash commits that should not appear in the history such as the one to fix this nit.

Done.

@greg0ire greg0ire requested review from SenseException, beberlei and morozov and removed request for beberlei October 11, 2024 17:09
@greg0ire greg0ire merged commit f1891f5 into doctrine:4.3.x Oct 11, 2024
91 of 92 checks passed
@greg0ire
Copy link
Member

Thanks @ausi !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants