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

4.x - Fix snapshot migration tests and index generation #628

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

ndm2
Copy link
Contributor

@ndm2 ndm2 commented Aug 31, 2023

This depends on / is blocked by cakephp/cakephp#17256 and cakephp/phinx#2212.

Without the test that this PR re-enables it has gone unnoticed at the time, but #617 uncovered some weird behavior, where Migrations will filter out all indexes that are created over the same columns as any foreign key, and then it uses the foreign keys in the templates to generate addIndex() calls for them, which results in the original index names getting lost, and indexes being created that do not necessarily exist.

I'm not quite sure whether that is a bug, or if it was intended in order to emulate how MySQL (the DBMS, not Migrations) would automatically created indexes in the source table when creating foreign keys (should no index already exist that covers it). The original code stems from a huge pile of changes that were part of the initial CakePHP 3 compatibility revamp, and there's no explanation or anything.

Personally I don't like it, I'd neither want to loose the index names, nor would I want a snapshot to create indexes that do not actually exist in my schema. So alongside of making the snapshot migration test work again, I would like to suggest making the index handling more strict, and only create addIndex() calls for indexes that actually exist.

@othercorey
Copy link
Member

othercorey commented Sep 13, 2023

@markstory @MasterOdin Can we unblock this? Need to figure out where the phinx merge will go.

@ndm2 ndm2 force-pushed the 4.x-fix-snapshot-migration-tests-and-index-generation branch from bd1c1d3 to ab33833 Compare September 14, 2023 18:45
@othercorey othercorey force-pushed the 4.x-fix-snapshot-migration-tests-and-index-generation branch from ab33833 to 98eb3cb Compare September 19, 2023 10:31
@ndm2 ndm2 force-pushed the 4.x-fix-snapshot-migration-tests-and-index-generation branch 2 times, most recently from 346a3b8 to 678f148 Compare September 22, 2023 01:44
Uses the actual unique index constraints to generate indexes, that way
the correct index name is being used, and it won't create indexes that
do not actually exist in the schema that is being snapshotted (this
might have been done to emulate MySQL, where indexes are automatically
created for foreign keys).
This should help to make identifying problems easier, as it's clear
whether the name denotes an index or a foreign key, and to
which tables they belong.
Uses the actual unique index constraints to generate indexes, that way
the correct index name is being used, and it won't create indexes that
do not actually exist in the schema that is being snapshotted (this
might have been done to emulate MySQL, where indexes are automatically
created for foreign keys).
This should help to make identifying problems easier, as it's clear
whether the name denotes an index or a foreign key, and to
which tables they belong.
@othercorey othercorey force-pushed the 4.x-fix-snapshot-migration-tests-and-index-generation branch from 678f148 to 741ff9b Compare September 22, 2023 04:43
@othercorey
Copy link
Member

Rebased with phinx 0.15.1 support.

@othercorey othercorey added this to the 4.x (CakePHP 5) milestone Sep 22, 2023
@othercorey othercorey merged commit 6966bea into 4.x Sep 22, 2023
10 checks passed
@othercorey othercorey deleted the 4.x-fix-snapshot-migration-tests-and-index-generation branch September 22, 2023 04:47
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.

2 participants