Skip to content

Commit 73878d5

Browse files
committed
[Rails51] Do not schema dump limits for certain types. Passes:
* SchemaDumperTest#test_schema_dump_does_not_include_limit_for_text_field * SchemaDumperTest#test_schema_dump_does_not_include_limit_for_binary_field
1 parent b6f8a77 commit 73878d5

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

lib/active_record/connection_adapters/sqlserver/schema_dumper.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ module ConnectionAdapters
33
module SQLServer
44
module SchemaDumper
55

6+
SQLSEVER_NO_LIMIT_TYPES = [
7+
'text',
8+
'ntext',
9+
'varchar(max)',
10+
'nvarchar(max)',
11+
'varbinary(max)'
12+
].freeze
13+
614
private
715

816
def explicit_primary_key_default?(column)
917
column.is_primary? && !column.is_identity?
1018
end
1119

20+
def schema_limit(column)
21+
return if SQLSEVER_NO_LIMIT_TYPES.include?(column.sql_type)
22+
super
23+
end
24+
1225
def schema_collation(column)
1326
return unless column.collation
1427
column.collation if column.collation != collation

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
3838
# Character Strings
3939
assert_line :char_10, type: 'char', limit: 10, precision: nil, scale: nil, default: "1234567890", collation: nil
4040
assert_line :varchar_50, type: 'varchar', limit: 50, precision: nil, scale: nil, default: "test varchar_50", collation: nil
41-
assert_line :varchar_max, type: 'varchar_max', limit: 2147483647, precision: nil, scale: nil, default: "test varchar_max", collation: nil
42-
assert_line :text, type: 'text_basic', limit: 2147483647, precision: nil, scale: nil, default: "test text", collation: nil
41+
assert_line :varchar_max, type: 'varchar_max', limit: nil, precision: nil, scale: nil, default: "test varchar_max", collation: nil
42+
assert_line :text, type: 'text_basic', limit: nil, precision: nil, scale: nil, default: "test text", collation: nil
4343
# Unicode Character Strings
4444
assert_line :nchar_10, type: 'nchar', limit: 10, precision: nil, scale: nil, default: "12345678åå", collation: nil
4545
assert_line :nvarchar_50, type: 'string', limit: 50, precision: nil, scale: nil, default: "test nvarchar_50 åå", collation: nil
46-
assert_line :nvarchar_max, type: 'text', limit: 2147483647, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
47-
assert_line :ntext, type: 'ntext', limit: 2147483647, precision: nil, scale: nil, default: "test ntext åå", collation: nil
46+
assert_line :nvarchar_max, type: 'text', limit: nil, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
47+
assert_line :ntext, type: 'ntext', limit: nil, precision: nil, scale: nil, default: "test ntext åå", collation: nil
4848
# Binary Strings
4949
assert_line :binary_49, type: 'binary_basic', limit: 49, precision: nil, scale: nil, default: nil
5050
assert_line :varbinary_49, type: 'varbinary', limit: 49, precision: nil, scale: nil, default: nil
51-
assert_line :varbinary_max, type: 'binary', limit: 2147483647, precision: nil, scale: nil, default: nil
51+
assert_line :varbinary_max, type: 'binary', limit: nil, precision: nil, scale: nil, default: nil
5252
# Other Data Types
5353
assert_line :uniqueidentifier, type: 'uuid', limit: nil, precision: nil, scale: nil, default: -> { "newid()" }
5454
assert_line :timestamp, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
@@ -76,12 +76,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
7676
assert_line :decimal_col, type: 'decimal', limit: nil, precision: 18, scale: 0, default: nil
7777
assert_line :float_col, type: 'float', limit: nil, precision: nil, scale: nil, default: nil
7878
assert_line :string_col, type: 'string', limit: nil, precision: nil, scale: nil, default: nil
79-
assert_line :text_col, type: 'text', limit: 2147483647, precision: nil, scale: nil, default: nil
79+
assert_line :text_col, type: 'text', limit: nil, precision: nil, scale: nil, default: nil
8080
assert_line :datetime_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
8181
assert_line :timestamp_col, type: 'datetime', limit: nil, precision: nil, scale: nil, default: nil
8282
assert_line :time_col, type: 'time', limit: nil, precision: 7, scale: nil, default: nil
8383
assert_line :date_col, type: 'date', limit: nil, precision: nil, scale: nil, default: nil
84-
assert_line :binary_col, type: 'binary', limit: 2147483647, precision: nil, scale: nil, default: nil
84+
assert_line :binary_col, type: 'binary', limit: nil, precision: nil, scale: nil, default: nil
8585
# Our type methods.
8686
columns['real_col'].sql_type.must_equal 'real'
8787
columns['money_col'].sql_type.must_equal 'money'
@@ -107,14 +107,14 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
107107
assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil
108108
assert_line :char_col, type: 'char', limit: 1, precision: nil, scale: nil, default: nil
109109
assert_line :varchar_col, type: 'varchar', limit: nil, precision: nil, scale: nil, default: nil
110-
assert_line :text_basic_col, type: 'text_basic', limit: 2147483647, precision: nil, scale: nil, default: nil
110+
assert_line :text_basic_col, type: 'text_basic', limit: nil, precision: nil, scale: nil, default: nil
111111
assert_line :nchar_col, type: 'nchar', limit: 1, precision: nil, scale: nil, default: nil
112-
assert_line :ntext_col, type: 'ntext', limit: 2147483647, precision: nil, scale: nil, default: nil
112+
assert_line :ntext_col, type: 'ntext', limit: nil, precision: nil, scale: nil, default: nil
113113
assert_line :binary_basic_col, type: 'binary_basic', limit: 1, precision: nil, scale: nil, default: nil
114114
assert_line :varbinary_col, type: 'varbinary', limit: nil, precision: nil, scale: nil, default: nil
115115
assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
116116
assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
117-
assert_line :json_col, type: 'text', limit: 2147483647, precision: nil, scale: nil, default: nil
117+
assert_line :json_col, type: 'text', limit: nil, precision: nil, scale: nil, default: nil
118118
end
119119

120120
# Special Cases

0 commit comments

Comments
 (0)