-
Notifications
You must be signed in to change notification settings - Fork 656
Allow bigint annotations in rails 4. #569
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
Conversation
In rails 4, columns do not respond to `bigint?`. However, in both rails 4 and rails 5, columns do respond to `sql_type`. This way, annotations should work in both versions.
`bigint(8)` is a bit redundant. Can just use bigint.
@ctran I would appreciate any suggestions on this one. Thanks! |
lib/annotate/annotate_models.rb
Outdated
@@ -362,7 +362,7 @@ def get_index_info(klass, options = {}) | |||
end | |||
|
|||
def get_col_type(col) | |||
if col.respond_to?(:bigint?) && col.bigint? | |||
if col.sql_type == 'bigint' |
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.
There seems to be some logic behind bigint?.
I'd change it to:
if (col.respond_to?(:bigint?) && col.bigint?) || /\Abigint\b/.match?(col.sql_type)
This way we'll pick up any logic from activerecord if it's implemented.
Thanks for the PR.
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.
Great call! Relying on the existing logic is much better than writing our own match.
@@ -183,7 +184,7 @@ def mock_column(name, type, options = {}) | |||
[ | |||
mock_column(:id, :integer), | |||
mock_column(:integer, :integer, unsigned?: true), | |||
mock_column(:bigint, :integer, unsigned?: true, bigint?: true), | |||
mock_column(:bigint, :integer, unsigned?: true, sql_type: 'bigint'), | |||
mock_column(:float, :float, unsigned?: true), |
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.
Can we test both of these?
- mock_column(:bigint, :integer, unsigned?: true, bigint?: true) # when bigint? is implemented
- mock_column(:bigint, :bigint, unsigned?: true) # when it's not
When using rails 5, it should use the logic already defined by ActiveRecord. When using rails <5, we should use very similar logic. Add spec to test for both cases.
Thanks for the feedback @ctran! Updated with both changes |
Thanks!!! |
In rails 4, columns do not respond to `bigint?`. However, in both rails 4 and rails 5, columns do respond to `sql_type`. This way, annotations should work in both versions.
In rails 4, columns do not respond to
bigint?
. However, in both rails4 and rails 5, columns do respond to
sql_type
. This way, annotationsshould work in both versions.
Very open to suggestions in specs! Should I change
mock_column
's signature tomock_column(name, type, sql_type, options ={})
?If the backstory is helpful, bigint annotating was originally added in #515.