Skip to content

Commit da91218

Browse files
committed
Support new type_to_sql arity.
1 parent d9c7f81 commit da91218

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def change_column(table_name, column_name, type, options = {})
130130
remove_indexes(table_name, column_name)
131131
end
132132
sql_commands << "UPDATE #{quote_table_name(table_name)} SET #{quote_column_name(column_name)}=#{quote_default_expression(options[:default], column_object)} WHERE #{quote_column_name(column_name)} IS NULL" if !options[:null].nil? && options[:null] == false && !options[:default].nil?
133-
sql_commands << "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
133+
sql_commands << "ALTER TABLE #{quote_table_name(table_name)} ALTER COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, limit: options[:limit], precision: options[:precision], scale: options[:scale])}"
134134
sql_commands[-1] << ' NOT NULL' if !options[:null].nil? && options[:null] == false
135135
if options_include_default?(options)
136136
sql_commands << "ALTER TABLE #{quote_table_name(table_name)} ADD CONSTRAINT #{default_constraint_name(table_name, column_name)} DEFAULT #{quote_default_expression(options[:default], column_object)} FOR #{quote_column_name(column_name)}"
@@ -194,7 +194,7 @@ def extract_foreign_key_action(action, fk_name)
194194
end
195195
end
196196

197-
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
197+
def type_to_sql(type, limit: nil, precision: nil, scale: nil, **)
198198
type_limitable = %w(string integer float char nchar varchar nvarchar).include?(type.to_s)
199199
limit = nil unless type_limitable
200200
case type.to_s
@@ -240,7 +240,7 @@ def change_column_null(table_name, column_name, allow_null, default = nil)
240240
if !allow_null.nil? && allow_null == false && !default.nil?
241241
do_execute("UPDATE #{table_id} SET #{column_id}=#{quote(default)} WHERE #{column_id} IS NULL")
242242
end
243-
sql = "ALTER TABLE #{table_id} ALTER COLUMN #{column_id} #{type_to_sql column.type, column.limit, column.precision, column.scale}"
243+
sql = "ALTER TABLE #{table_id} ALTER COLUMN #{column_id} #{type_to_sql column.type, limit: column.limit, precision: column.precision, scale: column.scale}"
244244
sql << ' NOT NULL' if !allow_null.nil? && allow_null == false
245245
do_execute sql
246246
end

test/cases/adapter_test_sqlserver.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,23 @@ class AdapterTestSQLServer < ActiveRecord::TestCase
265265
end
266266

267267
it 'create integers when limit is 4' do
268-
assert_equal 'integer', connection.type_to_sql(:integer, 4)
268+
assert_equal 'integer', connection.type_to_sql(:integer, limit: 4)
269269
end
270270

271271
it 'create integers when limit is 3' do
272-
assert_equal 'integer', connection.type_to_sql(:integer, 3)
272+
assert_equal 'integer', connection.type_to_sql(:integer, limit: 3)
273273
end
274274

275275
it 'create smallints when limit is less than 3' do
276-
assert_equal 'smallint', connection.type_to_sql(:integer, 2)
277-
assert_equal 'smallint', connection.type_to_sql(:integer, 1)
276+
assert_equal 'smallint', connection.type_to_sql(:integer, limit: 2)
277+
assert_equal 'smallint', connection.type_to_sql(:integer, limit: 1)
278278
end
279279

280280
it 'create bigints when limit is greateer than 4' do
281-
assert_equal 'bigint', connection.type_to_sql(:integer, 5)
282-
assert_equal 'bigint', connection.type_to_sql(:integer, 6)
283-
assert_equal 'bigint', connection.type_to_sql(:integer, 7)
284-
assert_equal 'bigint', connection.type_to_sql(:integer, 8)
281+
assert_equal 'bigint', connection.type_to_sql(:integer, limit: 5)
282+
assert_equal 'bigint', connection.type_to_sql(:integer, limit: 6)
283+
assert_equal 'bigint', connection.type_to_sql(:integer, limit: 7)
284+
assert_equal 'bigint', connection.type_to_sql(:integer, limit: 8)
285285
end
286286

287287
it 'create floats when no limit supplied' do

0 commit comments

Comments
 (0)