Skip to content

Commit 63cc88c

Browse files
willnetctran
authored andcommitted
Annotate bigint columns as 'bigint' instead of 'integer' (#515)
1 parent 5275757 commit 63cc88c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/annotate/annotate_models.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def get_schema_info(klass, header, options = {})
249249
cols = cols.sort_by(&:name) if options[:sort]
250250
cols = classified_sort(cols) if options[:classified_sort]
251251
cols.each do |col|
252-
col_type = (col.type || col.sql_type).to_s
252+
col_type = get_col_type(col)
253253
attrs = []
254254
attrs << "default(#{schema_default(klass, col)})" unless col.default.nil? || hide_default?(col_type, options)
255255
attrs << 'unsigned' if col.respond_to?(:unsigned?) && col.unsigned?
@@ -363,6 +363,14 @@ def get_index_info(klass, options = {})
363363
index_info
364364
end
365365

366+
def get_col_type(col)
367+
if col.respond_to?(:bigint?) && col.bigint?
368+
'bigint'
369+
else
370+
(col.type || col.sql_type).to_s
371+
end
372+
end
373+
366374
def index_columns_info(index)
367375
Array(index.columns).map do |col|
368376
if index.try(:orders) && index.orders[col.to_s]

spec/annotate/annotate_models_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def mock_column(name, type, options = {})
158158
[
159159
mock_column(:id, :integer),
160160
mock_column(:integer, :integer, unsigned?: true),
161-
mock_column(:bigint, :bigint, unsigned?: true),
161+
mock_column(:bigint, :integer, unsigned?: true, bigint?: true),
162162
mock_column(:float, :float, unsigned?: true),
163163
mock_column(:decimal, :decimal, unsigned?: true, precision: 10, scale: 2),
164164
])

0 commit comments

Comments
 (0)