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

Support renaming columns in migrations #2682

Merged
merged 5 commits into from
Nov 22, 2023

Conversation

hans-thomas
Copy link
Contributor

@hans-thomas hans-thomas commented Nov 19, 2023

Fix #2391
As mentioned in the linked issue, the renameColumn doesn't work. I just override that to fix the method.

@hans-thomas hans-thomas marked this pull request as ready for review November 19, 2023 13:50
Comment on lines +280 to +287
/** @inheritdoc */
public function renameColumn($from, $to)
{
$this->collection->updateMany([$from => ['$exists' => true]], ['$rename' => [$from => $to]]);

return $this;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First, it finds the documents that have the $from column and then runs a query to rename their column to the $to.

@alcaeus alcaeus changed the title Fixing Rename column in migration Support renaming columns in migrations Nov 20, 2023
@alcaeus alcaeus requested a review from GromNaN November 20, 2023 08:33
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

The test should be more focused, otherwise LGTM.

tests/SchemaTest.php Show resolved Hide resolved
@GromNaN GromNaN merged commit bcadf52 into mongodb:4.1 Nov 22, 2023
13 checks passed
@GromNaN
Copy link
Member

GromNaN commented Nov 22, 2023

Thank you @hans-thomas

Treggats pushed a commit to Treggats/laravel-mongodb that referenced this pull request Nov 22, 2023
@hans-thomas hans-thomas deleted the 2391-rename-column branch November 23, 2023 13:12
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.

Rename column in migration has no effect
3 participants