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

Whilelist existing assets we know about from metadata in SchemaTool::getUpdateSchemaSql() #7875

Merged
merged 3 commits into from
Dec 16, 2019

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Oct 21, 2019

This PR is a sidekick of doctrine/DoctrineBundle#1037

When generating schema diffs, if a source table is filtered out by a schema_filter expression, then a CREATE TABLE is always generated, even if the table already exists.

This PR makes SchemaTool::getUpdateSchemaSql() whitelist tables that are listed in the metadata we are generating the diff for, thus fixing the issue.

@nicolas-grekas nicolas-grekas force-pushed the schema-tool branch 5 times, most recently from 86c4ba2 to 40aa43f Compare October 21, 2019 22:05
@jwage
Copy link
Member

jwage commented Oct 22, 2019

I understand the problem and how it manifests itself to the end user. I've been running in to this in Symfony with the messenger tables. Kudos to you for taking a stab at fixing it. I always felt like the filter functionality was sort of half baked.

Can you think of any better way we could implement this to eliminate the nested closures?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 22, 2019

Passing $toFilter to createSchema()could be made to produce the desired behavior, or a new method dedicated to the need.

But that's an API change so it's out of reach for a bug fix on the ORM side. ORM 2.7 could bump to dbal 2.10 and clean the code afterwards (actually not because dbal 2.10 is planned to require PHP 7.2 apparently.)

@nicolas-grekas nicolas-grekas force-pushed the schema-tool branch 4 times, most recently from 562288a to 2abffee Compare October 23, 2019 16:22
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 23, 2019

Now with tests, courtesy of @l-vo, big thanks to him!

@nicolas-grekas nicolas-grekas force-pushed the schema-tool branch 3 times, most recently from 3541007 to ae645f0 Compare October 24, 2019 13:09
@alcaeus
Copy link
Member

alcaeus commented Oct 25, 2019

Looks good to me. As for the nested closures, there isn't much we can do since DBAL only takes a single closure as a filter. If you want to expand on that filter later on, there's no other option than to wrap it. In one of our bundles we have a chain to take care of that, but DBAL itself does not provide any helpers for this purpose.

Introducing a chain filter class would require this to go into 2.7 as it's a new API, so I'm ok with keeping the nested closures and treating this as a (long-awaited) bug fix in 2.6.

alcaeus
alcaeus previously approved these changes Oct 25, 2019
Ocramius
Ocramius previously approved these changes Oct 25, 2019
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

LGTM - discussed directly with @nicolas-grekas, and the use-case seems clear to me now 👍

@Ocramius
Copy link
Member

What I'm still puzzled on is BC compliance of this patch: we're now allowing the schema diffing to kick in for known symbols, which may break existing use-cases (where mappings were kept only as documentation, never really used by the ORM).

@doctrine/doctrinecore ideas?

@jwage
Copy link
Member

jwage commented Oct 26, 2019

It is definitely a "BC Break" but I am not sure in what ways it would manifest itself in desirable ways that someone would depend on, but who knows. In the problem Symfony team is trying to fix, the resulting SQL we produce just has to be manually edited by the developer before reviewing and executing to remove the tables that shouldn't be there.

jwage
jwage previously approved these changes Oct 26, 2019
@lcobucci lcobucci changed the base branch from 2.6 to 2.7 November 18, 2019 23:31
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

Just some small changes, we should be good to go soon.

@lcobucci
Copy link
Member

lcobucci commented Nov 19, 2019

I'll plan this for v2.7.1 so we don't miss this. I think it might be good to mention the minor BC-break in UPGRADE.md, what do you think @Ocramius?

@lcobucci lcobucci added this to the 2.7.1 milestone Nov 19, 2019
@nicolas-grekas nicolas-grekas dismissed stale reviews from jwage, Ocramius, and alcaeus via 0b59f2a November 20, 2019 14:27
@nicolas-grekas nicolas-grekas force-pushed the schema-tool branch 2 times, most recently from 0b59f2a to 6e7c39e Compare November 20, 2019 14:29
@nicolas-grekas
Copy link
Member Author

Comments addressed @lcobucci
I'll let you deal with the UPGRADE notes if you don't mind.

@alcaeus
Copy link
Member

alcaeus commented Nov 24, 2019

@lcobucci 2.7.1 sounds good, as does mentioning this in UPGRADE.md. I've pushed a commit to do this. Thanks @nicolas-grekas!

alcaeus
alcaeus previously approved these changes Nov 24, 2019
alcaeus
alcaeus previously approved these changes Nov 26, 2019
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

I've unified and simplified the test case too, LGTM.

Thanks @nicolas-grekas and @l-vo!

@lcobucci lcobucci merged commit 4a42262 into doctrine:2.7 Dec 16, 2019
@nicolas-grekas nicolas-grekas deleted the schema-tool branch April 29, 2020 16:13
@mvorisek
Copy link
Contributor

mvorisek commented Nov 7, 2020

@greg0ire why is this not merged in master?

@greg0ire
Copy link
Member

greg0ire commented Nov 7, 2020

@mvorisek because the last merge up to master is a few years old.

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.

9 participants