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 #570] Change of foreign key should be considered as a column change #678

Merged
merged 1 commit into from
Dec 18, 2019

Conversation

sashabelozerov
Copy link
Contributor

Fixes #570

@@ -515,7 +515,7 @@ def annotate_one_file(file_name, info_block, position, options = {})
old_header = old_content.match(header_pattern).to_s
new_header = info_block.match(header_pattern).to_s

column_pattern = /^#[\t ]+[\w\*`]+[\t ]+.+$/
column_pattern = /^#[\t ]+[\w\*\.`]+[\t ]+.+$/
Copy link
Owner

Choose a reason for hiding this comment

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

Could you leave a note as to why this would fix the problem?

Copy link
Contributor Author

@sashabelozerov sashabelozerov Dec 15, 2019

Choose a reason for hiding this comment

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

@ctran Line with a foreign key info in an annotation text looks like:

# fk_rails_... (foreign_thing_id => foreign_things.id) ON DELETE => restrict

It didn't match the previous pattern because of dots at the end of the foreign key name (we have dots there because we truncate generated foreign key names at https://github.com/ctran/annotate_models/blob/develop/lib/annotate/annotate_models.rb#L477).

In turn, because a foreign key line didn't match the pattern, we didn't check it for changes at https://github.com/ctran/annotate_models/blob/develop/lib/annotate/annotate_models.rb#L525

Changes in the pattern solves this case.

Hope this helps.

Copy link
Owner

Choose a reason for hiding this comment

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

Does it mean if the name doesn't end with "...", this pattern won't match anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ctran No. [\w\*\.`] - this part of the regexp represents characters which a name can consist of, in any order. It will match both names with "..." and without them.

@ctran ctran added this to the v3.1.0 milestone Dec 18, 2019
@ctran ctran merged commit 5219c7e into ctran:develop Dec 18, 2019
@ctran
Copy link
Owner

ctran commented Dec 18, 2019

Thanks!

peterfication pushed a commit to store2be/annotate_models that referenced this pull request Jan 20, 2020
vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
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.

foreign key change of type don't get noticed
2 participants