Skip to content

Commit 9040c24

Browse files
committed
Fix tinyint columns schema migration
1 parent 0dd5e98 commit 9040c24

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
220220
case type.to_s
221221
when 'integer'
222222
case limit
223-
when 1..2 then 'smallint'
223+
when 1 then 'tinyint'
224+
when 2 then 'smallint'
224225
when 3..4, nil then 'integer'
225226
when 5..8 then 'bigint'
226227
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")

test/cases/adapter_test_sqlserver.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,12 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
273273
assert_equal 'integer', connection.type_to_sql(:integer, limit: 3)
274274
end
275275

276-
it 'create smallints when limit is less than 3' do
276+
it 'create smallints when limit is 2' do
277277
assert_equal 'smallint', connection.type_to_sql(:integer, limit: 2)
278-
assert_equal 'smallint', connection.type_to_sql(:integer, limit: 1)
278+
end
279+
280+
it 'create tinyints when limit is 1' do
281+
assert_equal 'tinyint', connection.type_to_sql(:integer, limit: 1)
279282
end
280283

281284
it 'create bigints when limit is greateer than 4' do

0 commit comments

Comments
 (0)