From 1a639429346e2bbac0ff7922d063e7f337ea9f16 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 19 Feb 2025 11:50:26 +0000 Subject: [PATCH 1/2] Fix warning about symbol to string conversion being frozen in future --- .../sqlserver/schema_statements.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/active_record/connection_adapters/sqlserver/schema_statements.rb b/lib/active_record/connection_adapters/sqlserver/schema_statements.rb index c8382cc92..458f3c753 100644 --- a/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +++ b/lib/active_record/connection_adapters/sqlserver/schema_statements.rb @@ -323,11 +323,13 @@ def check_constraints(table_name) end def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) - type_limitable = %w[string integer float char nchar varchar nvarchar binary_basic].include?(type.to_s) + type = type.to_sym + + type_limitable = [:string, :integer, :float, :char, :nchar, :varchar, :nvarchar, :binary_basic].include?(type) limit = nil unless type_limitable - case type.to_s - when "integer" + case type + when :integer case limit when 1 then "tinyint" when 2 then "smallint" @@ -335,8 +337,8 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) when 5..8 then "bigint" else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.") end - when "time" # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql - column_type_sql = type.to_s + when :time # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql + column_type_sql = type.to_s.dup if precision if (0..7) === precision column_type_sql << "(#{precision})" @@ -345,7 +347,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) end end column_type_sql - when "datetime2" + when :datetime2 column_type_sql = super if precision if (0..7) === precision @@ -355,7 +357,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) end end column_type_sql - when "datetimeoffset" + when :datetimeoffset column_type_sql = super if precision if (0..7) === precision From 5f04134a4f1f3d1ecd1737bb0a84be92feb28290 Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 19 Feb 2025 13:04:17 +0000 Subject: [PATCH 2/2] Smaller fix --- .../sqlserver/schema_statements.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/active_record/connection_adapters/sqlserver/schema_statements.rb b/lib/active_record/connection_adapters/sqlserver/schema_statements.rb index 458f3c753..5f1e0f6dd 100644 --- a/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +++ b/lib/active_record/connection_adapters/sqlserver/schema_statements.rb @@ -323,13 +323,11 @@ def check_constraints(table_name) end def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) - type = type.to_sym - - type_limitable = [:string, :integer, :float, :char, :nchar, :varchar, :nvarchar, :binary_basic].include?(type) + type_limitable = %w[string integer float char nchar varchar nvarchar binary_basic].include?(type.to_s) limit = nil unless type_limitable - case type - when :integer + case type.to_s + when "integer" case limit when 1 then "tinyint" when 2 then "smallint" @@ -337,7 +335,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) when 5..8 then "bigint" else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.") end - when :time # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql + when "time" # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql column_type_sql = type.to_s.dup if precision if (0..7) === precision @@ -347,7 +345,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) end end column_type_sql - when :datetime2 + when "datetime2" column_type_sql = super if precision if (0..7) === precision @@ -357,7 +355,7 @@ def type_to_sql(type, limit: nil, precision: nil, scale: nil, **) end end column_type_sql - when :datetimeoffset + when "datetimeoffset" column_type_sql = super if precision if (0..7) === precision