-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[10.x] Guess table name correctly in migrations if column's name have ('to', 'from' and/or 'in') terms #48437
Conversation
const CHANGE_PATTERNS = [ | ||
'/_(to|from|in)_(\w+)_table$/', | ||
'/_(to|from|in)_(\w+)$/', | ||
'/_(to|from|in)_(?!.*?(\_to\_|\_in\_|\_from\_))(\w+)_table$/', | ||
'/_(to|from|in)_(?!.*?(\_to\_|\_in\_|\_from\_))(\w+)$/', | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just add .*
in the beginning of the regex, so '/_(to|from|in)_(\w+)$/'
becomes '/.*_(to|from|in)_(\w+)$/'
. Based on my testing it also solves the issue and makes regex simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But better double check it before applying, maybe I missed something :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall thanks for PR, I think it's useful for cases like you described.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@i350, good catch on the bug here. I agree with @hivokas though, this regex could be a little simpler, for example:
const CHANGE_PATTERNS = [
'/.+_(to|from|in)_(\w+)_table$/',
'/.+_(to|from|in)_(\w+)$/',
];
Given the greedy nature of regular expressions, this will force it to only match the "last" instance in the string. I quickly tried it with your new test cases in regex101. Feel free to update your PR and see if it works for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hivokas & @jasonmccreary
I just pushed an update to use the simplified regex you provided (52eac63)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work @i350
This PR improves the table guesser, to work correctly if the user trying make migration that add/update/delete column have one of the terms ("to", "from" or/and "in")
For example, if the user executed the command
The table name guesser before this update will return "3rd_party_service_column_to_users" as a table name, but after the update, it returns "users"