Skip to content

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

Merged
merged 3 commits into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module AnnotateModels

# Don't show limit (#) on these column types
# Example: show "integer" instead of "integer(4)"
NO_LIMIT_COL_TYPES = %w(integer boolean).freeze
NO_LIMIT_COL_TYPES = %w(integer bigint boolean).freeze

# Don't show default value for these column types
NO_DEFAULT_COL_TYPES = %w(json jsonb hstore).freeze
Expand Down Expand Up @@ -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.respond_to?(:bigint?) && col.bigint?) || /\Abigint\b/.match?(col.sql_type)
'bigint'
else
(col.type || col.sql_type).to_s
Expand Down
5 changes: 4 additions & 1 deletion spec/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def mock_column(name, type, options = {})
default_options = {
limit: nil,
null: false,
default: nil
default: nil,
sql_type: type
}

stubs = default_options.dup
Expand Down Expand Up @@ -184,6 +185,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, :bigint, unsigned?: true),
mock_column(:float, :float, unsigned?: true),
mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2),
])
Expand All @@ -196,6 +198,7 @@ def mock_column(name, type, options = {})
# id :integer not null
# integer :integer unsigned, not null
# bigint :bigint unsigned, not null
# bigint :bigint unsigned, not null
# float :float unsigned, not null
# decimal :decimal(10, 2) unsigned, not null
#
Expand Down