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

Fix recreating indices for renamed/removed columns. #2134

Conversation

ndm2
Copy link
Contributor

@ndm2 ndm2 commented Nov 1, 2022

A possible implementation to solve #2129, it ignores indices with expressions (which results in SQL errors accordingly when columns are missing on index recreation), and behaves like Postgres on column removal, ie it always removes the index, even composite ones.

Short of actually parsing the SQL, that regex for renaming is the best I could come up with so far. It can handle quite some variations, but I'm certainly not claiming that there aren't possibly cases where it would fail.

@ndm2 ndm2 force-pushed the 0.x-fix-recreating-indices-for-renamed-removed-columns branch 2 times, most recently from 6e859b0 to 1c9f9e9 Compare November 1, 2022 20:31
return $this->copyAndDropTmpTable($instructions, $tableName);
$instructions = $this->bufferIndicesAndTriggers($instructions, $tableName);
$instructions = $this->updateIndicesForRenamedColumn($instructions, $columnName, $newColumnName);
$instructions = $this->copyAndDropTmpTable($instructions, $tableName);
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on modifying copyAndDropTmpTable to accept an optional third and fourth arguments $columnName and newColumnName, and then copyAndDropTmpTable is responsible for calling bufferIndicesAndTriggers, updateIndicesForRenamedColumn, and recreateIndicesAndTriggers?

This would cut down on the boilerplate around using these as three of them are always used in conjunction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm very much open to some refactoring here, I don't really like all that repitition either. I actually had it like this at first, with the new methods added around the copy/delete post step:

copyAndDropTmpTable(AlterInstructions $instructions, string $tableName, string $deletedOrRenamedColumnName, string $newColumnName)

It was kinda bloated, and I thought that it wouldn't be overly appreciated.

How about a new method that combines all the post step addition methods, something like endAlterByCopyTable to complement beginAlterByCopyTable?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, I'd be open to having a complimentary endAlterByCopyTable that wraps these 4 function calls as-is, makes sense as we have a beginAlterByCopyTable.

@ndm2 ndm2 force-pushed the 0.x-fix-recreating-indices-for-renamed-removed-columns branch 2 times, most recently from 382f864 to a4c6476 Compare December 7, 2022 15:46
@dereuromark
Copy link
Member

@MasterOdin Can we move forward here? You still had it on request change

@ndm2
Copy link
Contributor Author

ndm2 commented Dec 22, 2022

As a heads up, ideally #2131 is merged first, it will make rebasing less awkward, as there needs to be some structural changes here in case the other PRs foreign key check behavior is being kept.

@dereuromark
Copy link
Member

ping @MasterOdin

@ndm2
Copy link
Contributor Author

ndm2 commented Dec 24, 2022

Just realized I've linked the wrong PR, I didn't mean to say that this one should to be merged first, but the table drop one, sorry 😬

@ndm2 ndm2 force-pushed the 0.x-fix-recreating-indices-for-renamed-removed-columns branch from a4c6476 to 2557451 Compare January 7, 2023 01:07
@ndm2 ndm2 force-pushed the 0.x-fix-recreating-indices-for-renamed-removed-columns branch from 2557451 to f6d45a8 Compare January 7, 2023 01:17
@dereuromark dereuromark merged commit a0fd9c8 into cakephp:0.x Jan 7, 2023
@ndm2 ndm2 deleted the 0.x-fix-recreating-indices-for-renamed-removed-columns branch August 3, 2023 16:02
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.

3 participants