activerecord-sqlserver-adapter 6.0.0.rc1 → 6.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +29 -0
- data/CHANGELOG.md +20 -0
- data/Gemfile +11 -5
- data/Guardfile +9 -8
- data/Rakefile +12 -16
- data/VERSION +1 -1
- data/activerecord-sqlserver-adapter.gemspec +3 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/active_record.rb +0 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/attribute_methods.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/calculations.rb +3 -4
- data/lib/active_record/connection_adapters/sqlserver/core_ext/explain.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/finder_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/core_ext/query_methods.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/database_statements.rb +35 -32
- data/lib/active_record/connection_adapters/sqlserver/database_tasks.rb +7 -12
- data/lib/active_record/connection_adapters/sqlserver/errors.rb +0 -3
- data/lib/active_record/connection_adapters/sqlserver/quoting.rb +8 -8
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/schema_dumper.rb +7 -7
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +106 -103
- data/lib/active_record/connection_adapters/sqlserver/showplan.rb +6 -8
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_table.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/showplan/printer_xml.rb +1 -1
- data/lib/active_record/connection_adapters/sqlserver/sql_type_metadata.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/table_definition.rb +1 -4
- data/lib/active_record/connection_adapters/sqlserver/transaction.rb +4 -8
- data/lib/active_record/connection_adapters/sqlserver/type.rb +35 -35
- data/lib/active_record/connection_adapters/sqlserver/type/big_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/binary.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/boolean.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/char.rb +2 -2
- data/lib/active_record/connection_adapters/sqlserver/type/data.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/date.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/datetime2.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/decimal.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/float.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/json.rb +0 -1
- data/lib/active_record/connection_adapters/sqlserver/type/money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/real.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/small_money.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/smalldatetime.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/time.rb +2 -3
- data/lib/active_record/connection_adapters/sqlserver/type/time_value_fractional.rb +6 -9
- data/lib/active_record/connection_adapters/sqlserver/type/timestamp.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/tiny_integer.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_char.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_string.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_text.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/unicode_varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/uuid.rb +1 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varbinary_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/type/varchar.rb +1 -3
- data/lib/active_record/connection_adapters/sqlserver/type/varchar_max.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver/utils.rb +8 -11
- data/lib/active_record/connection_adapters/sqlserver/version.rb +0 -2
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +85 -83
- data/lib/active_record/connection_adapters/sqlserver_column.rb +0 -2
- data/lib/active_record/sqlserver_base.rb +1 -1
- data/lib/active_record/tasks/sqlserver_database_tasks.rb +26 -32
- data/lib/activerecord-sqlserver-adapter.rb +1 -1
- data/lib/arel/visitors/sqlserver.rb +18 -14
- data/lib/arel_sqlserver.rb +2 -2
- data/test/cases/adapter_test_sqlserver.rb +161 -182
- data/test/cases/change_column_null_test_sqlserver.rb +12 -12
- data/test/cases/coerced_tests.rb +88 -270
- data/test/cases/column_test_sqlserver.rb +281 -283
- data/test/cases/connection_test_sqlserver.rb +15 -20
- data/test/cases/execute_procedure_test_sqlserver.rb +18 -20
- data/test/cases/fetch_test_sqlserver.rb +14 -22
- data/test/cases/fully_qualified_identifier_test_sqlserver.rb +12 -18
- data/test/cases/helper_sqlserver.rb +13 -15
- data/test/cases/in_clause_test_sqlserver.rb +9 -9
- data/test/cases/index_test_sqlserver.rb +13 -15
- data/test/cases/json_test_sqlserver.rb +23 -25
- data/test/cases/migration_test_sqlserver.rb +22 -28
- data/test/cases/order_test_sqlserver.rb +51 -54
- data/test/cases/pessimistic_locking_test_sqlserver.rb +25 -33
- data/test/cases/rake_test_sqlserver.rb +31 -45
- data/test/cases/schema_dumper_test_sqlserver.rb +104 -108
- data/test/cases/schema_test_sqlserver.rb +18 -26
- data/test/cases/scratchpad_test_sqlserver.rb +2 -4
- data/test/cases/showplan_test_sqlserver.rb +24 -33
- data/test/cases/specific_schema_test_sqlserver.rb +66 -65
- data/test/cases/transaction_test_sqlserver.rb +16 -19
- data/test/cases/trigger_test_sqlserver.rb +12 -12
- data/test/cases/utils_test_sqlserver.rb +68 -70
- data/test/cases/uuid_test_sqlserver.rb +11 -13
- data/test/debug.rb +6 -6
- data/test/migrations/create_clients_and_change_column_null.rb +1 -1
- data/test/migrations/transaction_table/1_table_will_never_be_created.rb +2 -4
- data/test/models/sqlserver/booking.rb +1 -1
- data/test/models/sqlserver/customers_view.rb +1 -1
- data/test/models/sqlserver/dollar_table_name.rb +1 -1
- data/test/models/sqlserver/edge_schema.rb +1 -3
- data/test/models/sqlserver/fk_has_fk.rb +1 -1
- data/test/models/sqlserver/fk_has_pk.rb +1 -1
- data/test/models/sqlserver/natural_pk_data.rb +2 -2
- data/test/models/sqlserver/natural_pk_int_data.rb +1 -1
- data/test/models/sqlserver/no_pk_data.rb +1 -1
- data/test/models/sqlserver/object_default.rb +1 -1
- data/test/models/sqlserver/quoted_table.rb +2 -2
- data/test/models/sqlserver/quoted_view_1.rb +1 -1
- data/test/models/sqlserver/quoted_view_2.rb +1 -1
- data/test/models/sqlserver/sst_memory.rb +1 -1
- data/test/models/sqlserver/string_default.rb +1 -1
- data/test/models/sqlserver/string_defaults_big_view.rb +1 -1
- data/test/models/sqlserver/string_defaults_view.rb +1 -1
- data/test/models/sqlserver/tinyint_pk.rb +1 -1
- data/test/models/sqlserver/trigger.rb +2 -2
- data/test/models/sqlserver/trigger_history.rb +1 -1
- data/test/models/sqlserver/upper.rb +1 -1
- data/test/models/sqlserver/uppered.rb +1 -1
- data/test/models/sqlserver/uuid.rb +1 -1
- data/test/schema/sqlserver_specific_schema.rb +20 -22
- data/test/support/coerceable_test_sqlserver.rb +1 -4
- data/test/support/connection_reflection.rb +1 -2
- data/test/support/core_ext/query_cache.rb +1 -1
- data/test/support/load_schema_sqlserver.rb +3 -5
- data/test/support/minitest_sqlserver.rb +1 -1
- data/test/support/paths_sqlserver.rb +9 -11
- data/test/support/rake_helpers.rb +12 -10
- data/test/support/sql_counter_sqlserver.rb +0 -4
- data/test/support/test_in_memory_oltp.rb +7 -7
- metadata +5 -4
@@ -1,20 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "cases/helper_sqlserver"
|
4
4
|
|
5
5
|
class SQLServerRakeTest < ActiveRecord::TestCase
|
6
|
-
|
7
6
|
self.use_transactional_tests = false
|
8
7
|
|
9
8
|
cattr_accessor :azure_skip
|
10
9
|
self.azure_skip = connection_sqlserver_azure?
|
11
10
|
|
12
11
|
let(:db_tasks) { ActiveRecord::Tasks::DatabaseTasks }
|
13
|
-
let(:new_database) {
|
14
|
-
let(:default_configuration) { ARTest.connection_config[
|
15
|
-
let(:configuration) { default_configuration.merge(
|
12
|
+
let(:new_database) { "activerecord_unittest_tasks" }
|
13
|
+
let(:default_configuration) { ARTest.connection_config["arunit"] }
|
14
|
+
let(:configuration) { default_configuration.merge("database" => new_database) }
|
16
15
|
|
17
|
-
before { skip
|
16
|
+
before { skip "on azure" if azure_skip }
|
18
17
|
before { disconnect! unless azure_skip }
|
19
18
|
after { reconnect unless azure_skip }
|
20
19
|
|
@@ -27,7 +26,7 @@ class SQLServerRakeTest < ActiveRecord::TestCase
|
|
27
26
|
def reconnect
|
28
27
|
config = default_configuration
|
29
28
|
if connection_sqlserver_azure?
|
30
|
-
ActiveRecord::Base.establish_connection(config.merge(
|
29
|
+
ActiveRecord::Base.establish_connection(config.merge("database" => "master"))
|
31
30
|
connection.drop_database(new_database) rescue nil
|
32
31
|
disconnect!
|
33
32
|
ActiveRecord::Base.establish_connection(config)
|
@@ -36,57 +35,51 @@ class SQLServerRakeTest < ActiveRecord::TestCase
|
|
36
35
|
connection.drop_database(new_database) rescue nil
|
37
36
|
end
|
38
37
|
end
|
39
|
-
|
40
38
|
end
|
41
39
|
|
42
40
|
class SQLServerRakeCreateTest < SQLServerRakeTest
|
43
|
-
|
44
41
|
self.azure_skip = false
|
45
42
|
|
46
|
-
it
|
43
|
+
it "establishes connection to database after create " do
|
47
44
|
quietly { db_tasks.create configuration }
|
48
45
|
_(connection.current_database).must_equal(new_database)
|
49
46
|
end
|
50
47
|
|
51
|
-
it
|
48
|
+
it "creates database with default collation" do
|
52
49
|
quietly { db_tasks.create configuration }
|
53
|
-
_(connection.collation).must_equal
|
50
|
+
_(connection.collation).must_equal "SQL_Latin1_General_CP1_CI_AS"
|
54
51
|
end
|
55
52
|
|
56
|
-
it
|
57
|
-
quietly { db_tasks.create configuration.merge(
|
58
|
-
_(connection.collation).must_equal
|
53
|
+
it "creates database with given collation" do
|
54
|
+
quietly { db_tasks.create configuration.merge("collation" => "Latin1_General_CI_AS") }
|
55
|
+
_(connection.collation).must_equal "Latin1_General_CI_AS"
|
59
56
|
end
|
60
57
|
|
61
|
-
it
|
58
|
+
it "prints error message when database exists" do
|
62
59
|
quietly { db_tasks.create configuration }
|
63
60
|
message = capture(:stderr) { db_tasks.create configuration }
|
64
61
|
_(message).must_match %r{activerecord_unittest_tasks.*already exists}
|
65
62
|
end
|
66
|
-
|
67
63
|
end
|
68
64
|
|
69
65
|
class SQLServerRakeDropTest < SQLServerRakeTest
|
70
|
-
|
71
66
|
self.azure_skip = false
|
72
67
|
|
73
|
-
it
|
68
|
+
it "drops database and uses master" do
|
74
69
|
quietly do
|
75
70
|
db_tasks.create configuration
|
76
71
|
db_tasks.drop configuration
|
77
72
|
end
|
78
|
-
_(connection.current_database).must_equal
|
73
|
+
_(connection.current_database).must_equal "master"
|
79
74
|
end
|
80
75
|
|
81
|
-
it
|
82
|
-
message = capture(:stderr) { db_tasks.drop configuration.merge(
|
76
|
+
it "prints error message when database does not exist" do
|
77
|
+
message = capture(:stderr) { db_tasks.drop configuration.merge("database" => "doesnotexist") }
|
83
78
|
_(message).must_match %r{'doesnotexist' does not exist}
|
84
79
|
end
|
85
|
-
|
86
80
|
end
|
87
81
|
|
88
82
|
class SQLServerRakePurgeTest < SQLServerRakeTest
|
89
|
-
|
90
83
|
before do
|
91
84
|
quietly { db_tasks.create(configuration) }
|
92
85
|
connection.create_table :users, force: true do |t|
|
@@ -95,43 +88,37 @@ class SQLServerRakePurgeTest < SQLServerRakeTest
|
|
95
88
|
end
|
96
89
|
end
|
97
90
|
|
98
|
-
it
|
91
|
+
it "clears active connections, drops database, and recreates with established connection" do
|
99
92
|
_(connection.current_database).must_equal(new_database)
|
100
|
-
_(connection.tables).must_include
|
93
|
+
_(connection.tables).must_include "users"
|
101
94
|
quietly { db_tasks.purge(configuration) }
|
102
95
|
_(connection.current_database).must_equal(new_database)
|
103
|
-
_(connection.tables).wont_include
|
96
|
+
_(connection.tables).wont_include "users"
|
104
97
|
end
|
105
|
-
|
106
98
|
end
|
107
99
|
|
108
100
|
class SQLServerRakeCharsetTest < SQLServerRakeTest
|
109
|
-
|
110
101
|
before do
|
111
102
|
quietly { db_tasks.create(configuration) }
|
112
103
|
end
|
113
104
|
|
114
|
-
it
|
115
|
-
_(db_tasks.charset(configuration)).must_equal
|
105
|
+
it "retrieves charset" do
|
106
|
+
_(db_tasks.charset(configuration)).must_equal "iso_1"
|
116
107
|
end
|
117
|
-
|
118
108
|
end
|
119
109
|
|
120
110
|
class SQLServerRakeCollationTest < SQLServerRakeTest
|
121
|
-
|
122
111
|
before do
|
123
112
|
quietly { db_tasks.create(configuration) }
|
124
113
|
end
|
125
114
|
|
126
|
-
it
|
127
|
-
_(db_tasks.collation(configuration)).must_equal
|
115
|
+
it "retrieves collation" do
|
116
|
+
_(db_tasks.collation(configuration)).must_equal "SQL_Latin1_General_CP1_CI_AS"
|
128
117
|
end
|
129
|
-
|
130
118
|
end
|
131
119
|
|
132
120
|
class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
|
133
|
-
|
134
|
-
let(:filename) { File.join ARTest::SQLServer.migrations_root, 'structure.sql' }
|
121
|
+
let(:filename) { File.join ARTest::SQLServer.migrations_root, "structure.sql" }
|
135
122
|
let(:filedata) { File.read(filename) }
|
136
123
|
|
137
124
|
before do
|
@@ -148,8 +135,8 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
|
|
148
135
|
FileUtils.rm_rf(filename)
|
149
136
|
end
|
150
137
|
|
151
|
-
it
|
152
|
-
skip
|
138
|
+
it "dumps structure and accounts for defncopy oddities" do
|
139
|
+
skip "debug defncopy on windows later" if host_windows?
|
153
140
|
quietly { db_tasks.structure_dump configuration, filename }
|
154
141
|
_(filedata).wont_match %r{\AUSE.*\z}
|
155
142
|
_(filedata).wont_match %r{\AGO.*\z}
|
@@ -158,14 +145,13 @@ class SQLServerRakeStructureDumpLoadTest < SQLServerRakeTest
|
|
158
145
|
_(filedata).must_match %r{background2\s+text\s+}
|
159
146
|
end
|
160
147
|
|
161
|
-
it
|
162
|
-
skip
|
148
|
+
it "can load dumped structure" do
|
149
|
+
skip "debug defncopy on windows later" if host_windows?
|
163
150
|
quietly { db_tasks.structure_dump configuration, filename }
|
164
151
|
_(filedata).must_match %r{CREATE TABLE dbo\.users}
|
165
152
|
db_tasks.purge(configuration)
|
166
|
-
_(connection.tables).wont_include
|
153
|
+
_(connection.tables).wont_include "users"
|
167
154
|
db_tasks.load_schema configuration, :sql, filename
|
168
|
-
_(connection.tables).must_include
|
155
|
+
_(connection.tables).must_include "users"
|
169
156
|
end
|
170
|
-
|
171
157
|
end
|
@@ -1,146 +1,144 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "cases/helper_sqlserver"
|
4
4
|
|
5
5
|
class SchemaDumperTestSQLServer < ActiveRecord::TestCase
|
6
|
-
|
7
6
|
before { all_tables }
|
8
7
|
|
9
8
|
let(:all_tables) { ActiveRecord::Base.connection.tables }
|
10
9
|
let(:schema) { @generated_schema }
|
11
10
|
|
12
|
-
it
|
13
|
-
generate_schema_for_table
|
14
|
-
assert_line :bigint, type:
|
15
|
-
assert_line :int, type:
|
16
|
-
assert_line :smallint, type:
|
17
|
-
assert_line :tinyint, type:
|
18
|
-
assert_line :bit, type:
|
19
|
-
assert_line :decimal_9_2, type:
|
20
|
-
assert_line :numeric_18_0, type:
|
21
|
-
assert_line :numeric_36_2, type:
|
22
|
-
assert_line :money, type:
|
23
|
-
assert_line :smallmoney, type:
|
11
|
+
it "sst_datatypes" do
|
12
|
+
generate_schema_for_table "sst_datatypes"
|
13
|
+
assert_line :bigint, type: "bigint", limit: nil, precision: nil, scale: nil, default: 42
|
14
|
+
assert_line :int, type: "integer", limit: nil, precision: nil, scale: nil, default: 42
|
15
|
+
assert_line :smallint, type: "integer", limit: 2, precision: nil, scale: nil, default: 42
|
16
|
+
assert_line :tinyint, type: "integer", limit: 1, precision: nil, scale: nil, default: 42
|
17
|
+
assert_line :bit, type: "boolean", limit: nil, precision: nil, scale: nil, default: true
|
18
|
+
assert_line :decimal_9_2, type: "decimal", limit: nil, precision: 9, scale: 2, default: 12345.01
|
19
|
+
assert_line :numeric_18_0, type: "decimal", limit: nil, precision: 18, scale: 0, default: 191.0
|
20
|
+
assert_line :numeric_36_2, type: "decimal", limit: nil, precision: 36, scale: 2, default: 12345678901234567890.01
|
21
|
+
assert_line :money, type: "money", limit: nil, precision: 19, scale: 4, default: 4.2
|
22
|
+
assert_line :smallmoney, type: "smallmoney", limit: nil, precision: 10, scale: 4, default: 4.2
|
24
23
|
# Approximate Numerics
|
25
|
-
assert_line :float, type:
|
26
|
-
assert_line :real, type:
|
24
|
+
assert_line :float, type: "float", limit: nil, precision: nil, scale: nil, default: 123.00000001
|
25
|
+
assert_line :real, type: "real", limit: nil, precision: nil, scale: nil, default: 123.45
|
27
26
|
# Date and Time
|
28
|
-
assert_line :date, type:
|
29
|
-
assert_line :datetime, type:
|
27
|
+
assert_line :date, type: "date", limit: nil, precision: nil, scale: nil, default: "01-01-0001"
|
28
|
+
assert_line :datetime, type: "datetime", limit: nil, precision: nil, scale: nil, default: "01-01-1753 00:00:00.123"
|
30
29
|
if connection_dblib_73?
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
assert_line :datetime2_7, type: "datetime", limit: nil, precision: 7, scale: nil, default: "12-31-9999 23:59:59.9999999"
|
31
|
+
assert_line :datetime2_3, type: "datetime", limit: nil, precision: 3, scale: nil, default: nil
|
32
|
+
assert_line :datetime2_1, type: "datetime", limit: nil, precision: 1, scale: nil, default: nil
|
34
33
|
end
|
35
|
-
assert_line :smalldatetime,
|
34
|
+
assert_line :smalldatetime, type: "smalldatetime", limit: nil, precision: nil, scale: nil, default: "01-01-1901 15:45:00.0"
|
36
35
|
if connection_dblib_73?
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
assert_line :time_7, type: "time", limit: nil, precision: 7, scale: nil, default: "04:20:00.2883215"
|
37
|
+
assert_line :time_2, type: "time", limit: nil, precision: 2, scale: nil, default: nil
|
38
|
+
assert_line :time_default, type: "time", limit: nil, precision: 7, scale: nil, default: "15:03:42.0621978"
|
40
39
|
end
|
41
40
|
# Character Strings
|
42
|
-
assert_line :char_10, type:
|
43
|
-
assert_line :varchar_50, type:
|
44
|
-
assert_line :varchar_max, type:
|
45
|
-
assert_line :text, type:
|
41
|
+
assert_line :char_10, type: "char", limit: 10, precision: nil, scale: nil, default: "1234567890", collation: nil
|
42
|
+
assert_line :varchar_50, type: "varchar", limit: 50, precision: nil, scale: nil, default: "test varchar_50", collation: nil
|
43
|
+
assert_line :varchar_max, type: "varchar_max", limit: nil, precision: nil, scale: nil, default: "test varchar_max", collation: nil
|
44
|
+
assert_line :text, type: "text_basic", limit: nil, precision: nil, scale: nil, default: "test text", collation: nil
|
46
45
|
# Unicode Character Strings
|
47
|
-
assert_line :nchar_10, type:
|
48
|
-
assert_line :nvarchar_50, type:
|
49
|
-
assert_line :nvarchar_max, type:
|
50
|
-
assert_line :ntext, type:
|
46
|
+
assert_line :nchar_10, type: "nchar", limit: 10, precision: nil, scale: nil, default: "12345678åå", collation: nil
|
47
|
+
assert_line :nvarchar_50, type: "string", limit: 50, precision: nil, scale: nil, default: "test nvarchar_50 åå", collation: nil
|
48
|
+
assert_line :nvarchar_max, type: "text", limit: nil, precision: nil, scale: nil, default: "test nvarchar_max åå", collation: nil
|
49
|
+
assert_line :ntext, type: "ntext", limit: nil, precision: nil, scale: nil, default: "test ntext åå", collation: nil
|
51
50
|
# Binary Strings
|
52
|
-
assert_line :binary_49, type:
|
53
|
-
assert_line :varbinary_49, type:
|
54
|
-
assert_line :varbinary_max, type:
|
51
|
+
assert_line :binary_49, type: "binary_basic", limit: 49, precision: nil, scale: nil, default: nil
|
52
|
+
assert_line :varbinary_49, type: "varbinary", limit: 49, precision: nil, scale: nil, default: nil
|
53
|
+
assert_line :varbinary_max, type: "binary", limit: nil, precision: nil, scale: nil, default: nil
|
55
54
|
# Other Data Types
|
56
|
-
assert_line :uniqueidentifier, type:
|
57
|
-
assert_line :timestamp, type:
|
55
|
+
assert_line :uniqueidentifier, type: "uuid", limit: nil, precision: nil, scale: nil, default: -> { "newid()" }
|
56
|
+
assert_line :timestamp, type: "ss_timestamp", limit: nil, precision: nil, scale: nil, default: nil
|
58
57
|
end
|
59
58
|
|
60
|
-
it
|
59
|
+
it "sst_datatypes_migration" do
|
61
60
|
columns = SSTestDatatypeMigration.columns_hash
|
62
|
-
generate_schema_for_table
|
61
|
+
generate_schema_for_table "sst_datatypes_migration"
|
63
62
|
# Simple Rails conventions
|
64
|
-
_(columns[
|
65
|
-
_(columns[
|
66
|
-
_(columns[
|
67
|
-
_(columns[
|
68
|
-
_(columns[
|
69
|
-
_(columns[
|
70
|
-
_(columns[
|
71
|
-
_(columns[
|
72
|
-
_(columns[
|
73
|
-
_(columns[
|
74
|
-
_(columns[
|
75
|
-
_(columns[
|
76
|
-
assert_line :integer_col, type:
|
77
|
-
assert_line :bigint_col, type:
|
78
|
-
assert_line :boolean_col, type:
|
79
|
-
assert_line :decimal_col, type:
|
80
|
-
assert_line :float_col, type:
|
81
|
-
assert_line :string_col, type:
|
82
|
-
assert_line :text_col, type:
|
83
|
-
assert_line :datetime_col, type:
|
84
|
-
assert_line :timestamp_col, type:
|
85
|
-
assert_line :time_col, type:
|
86
|
-
assert_line :date_col, type:
|
87
|
-
assert_line :binary_col, type:
|
63
|
+
_(columns["integer_col"].sql_type).must_equal "int(4)"
|
64
|
+
_(columns["bigint_col"].sql_type).must_equal "bigint(8)"
|
65
|
+
_(columns["boolean_col"].sql_type).must_equal "bit"
|
66
|
+
_(columns["decimal_col"].sql_type).must_equal "decimal(18,0)"
|
67
|
+
_(columns["float_col"].sql_type).must_equal "float"
|
68
|
+
_(columns["string_col"].sql_type).must_equal "nvarchar(4000)"
|
69
|
+
_(columns["text_col"].sql_type).must_equal "nvarchar(max)"
|
70
|
+
_(columns["datetime_col"].sql_type).must_equal "datetime"
|
71
|
+
_(columns["timestamp_col"].sql_type).must_equal "datetime"
|
72
|
+
_(columns["time_col"].sql_type).must_equal "time(7)"
|
73
|
+
_(columns["date_col"].sql_type).must_equal "date"
|
74
|
+
_(columns["binary_col"].sql_type).must_equal "varbinary(max)"
|
75
|
+
assert_line :integer_col, type: "integer", limit: nil, precision: nil, scale: nil, default: nil
|
76
|
+
assert_line :bigint_col, type: "bigint", limit: nil, precision: nil, scale: nil, default: nil
|
77
|
+
assert_line :boolean_col, type: "boolean", limit: nil, precision: nil, scale: nil, default: nil
|
78
|
+
assert_line :decimal_col, type: "decimal", limit: nil, precision: 18, scale: 0, default: nil
|
79
|
+
assert_line :float_col, type: "float", limit: nil, precision: nil, scale: nil, default: nil
|
80
|
+
assert_line :string_col, type: "string", limit: nil, precision: nil, scale: nil, default: nil
|
81
|
+
assert_line :text_col, type: "text", limit: nil, precision: nil, scale: nil, default: nil
|
82
|
+
assert_line :datetime_col, type: "datetime", limit: nil, precision: nil, scale: nil, default: nil
|
83
|
+
assert_line :timestamp_col, type: "datetime", limit: nil, precision: nil, scale: nil, default: nil
|
84
|
+
assert_line :time_col, type: "time", limit: nil, precision: 7, scale: nil, default: nil
|
85
|
+
assert_line :date_col, type: "date", limit: nil, precision: nil, scale: nil, default: nil
|
86
|
+
assert_line :binary_col, type: "binary", limit: nil, precision: nil, scale: nil, default: nil
|
88
87
|
# Our type methods.
|
89
|
-
_(columns[
|
90
|
-
_(columns[
|
91
|
-
_(columns[
|
92
|
-
_(columns[
|
93
|
-
_(columns[
|
94
|
-
_(columns[
|
95
|
-
_(columns[
|
96
|
-
_(columns[
|
97
|
-
_(columns[
|
98
|
-
_(columns[
|
99
|
-
_(columns[
|
100
|
-
_(columns[
|
101
|
-
_(columns[
|
102
|
-
_(columns[
|
103
|
-
_(columns[
|
104
|
-
_(columns[
|
105
|
-
assert_line :real_col, type:
|
106
|
-
assert_line :money_col, type:
|
107
|
-
assert_line :smalldatetime_col, type:
|
108
|
-
assert_line :datetime2_col, type:
|
109
|
-
assert_line :datetimeoffset, type:
|
110
|
-
assert_line :smallmoney_col, type:
|
111
|
-
assert_line :char_col, type:
|
112
|
-
assert_line :varchar_col, type:
|
113
|
-
assert_line :text_basic_col, type:
|
114
|
-
assert_line :nchar_col, type:
|
115
|
-
assert_line :ntext_col, type:
|
116
|
-
assert_line :binary_basic_col, type:
|
117
|
-
assert_line :varbinary_col, type:
|
118
|
-
assert_line :uuid_col, type:
|
119
|
-
assert_line :sstimestamp_col, type:
|
120
|
-
assert_line :json_col, type:
|
88
|
+
_(columns["real_col"].sql_type).must_equal "real"
|
89
|
+
_(columns["money_col"].sql_type).must_equal "money"
|
90
|
+
_(columns["smalldatetime_col"].sql_type).must_equal "smalldatetime"
|
91
|
+
_(columns["datetime2_col"].sql_type).must_equal "datetime2(7)"
|
92
|
+
_(columns["datetimeoffset"].sql_type).must_equal "datetimeoffset(7)"
|
93
|
+
_(columns["smallmoney_col"].sql_type).must_equal "smallmoney"
|
94
|
+
_(columns["char_col"].sql_type).must_equal "char(1)"
|
95
|
+
_(columns["varchar_col"].sql_type).must_equal "varchar(8000)"
|
96
|
+
_(columns["text_basic_col"].sql_type).must_equal "text"
|
97
|
+
_(columns["nchar_col"].sql_type).must_equal "nchar(1)"
|
98
|
+
_(columns["ntext_col"].sql_type).must_equal "ntext"
|
99
|
+
_(columns["binary_basic_col"].sql_type).must_equal "binary(1)"
|
100
|
+
_(columns["varbinary_col"].sql_type).must_equal "varbinary(8000)"
|
101
|
+
_(columns["uuid_col"].sql_type).must_equal "uniqueidentifier"
|
102
|
+
_(columns["sstimestamp_col"].sql_type).must_equal "timestamp"
|
103
|
+
_(columns["json_col"].sql_type).must_equal "nvarchar(max)"
|
104
|
+
assert_line :real_col, type: "real", limit: nil, precision: nil, scale: nil, default: nil
|
105
|
+
assert_line :money_col, type: "money", limit: nil, precision: 19, scale: 4, default: nil
|
106
|
+
assert_line :smalldatetime_col, type: "smalldatetime", limit: nil, precision: nil, scale: nil, default: nil
|
107
|
+
assert_line :datetime2_col, type: "datetime", limit: nil, precision: 7, scale: nil, default: nil
|
108
|
+
assert_line :datetimeoffset, type: "datetimeoffset", limit: nil, precision: 7, scale: nil, default: nil
|
109
|
+
assert_line :smallmoney_col, type: "smallmoney", limit: nil, precision: 10, scale: 4, default: nil
|
110
|
+
assert_line :char_col, type: "char", limit: 1, precision: nil, scale: nil, default: nil
|
111
|
+
assert_line :varchar_col, type: "varchar", limit: nil, precision: nil, scale: nil, default: nil
|
112
|
+
assert_line :text_basic_col, type: "text_basic", limit: nil, precision: nil, scale: nil, default: nil
|
113
|
+
assert_line :nchar_col, type: "nchar", limit: 1, precision: nil, scale: nil, default: nil
|
114
|
+
assert_line :ntext_col, type: "ntext", limit: nil, precision: nil, scale: nil, default: nil
|
115
|
+
assert_line :binary_basic_col, type: "binary_basic", limit: 1, precision: nil, scale: nil, default: nil
|
116
|
+
assert_line :varbinary_col, type: "varbinary", limit: nil, precision: nil, scale: nil, default: nil
|
117
|
+
assert_line :uuid_col, type: "uuid", limit: nil, precision: nil, scale: nil, default: nil
|
118
|
+
assert_line :sstimestamp_col, type: "ss_timestamp", limit: nil, precision: nil, scale: nil, default: nil
|
119
|
+
assert_line :json_col, type: "text", limit: nil, precision: nil, scale: nil, default: nil
|
121
120
|
end
|
122
121
|
|
123
122
|
# Special Cases
|
124
123
|
|
125
|
-
it
|
126
|
-
generate_schema_for_table(
|
124
|
+
it "honor nonstandard primary keys" do
|
125
|
+
generate_schema_for_table("movies") do |output|
|
127
126
|
match = output.match(%r{create_table "movies"(.*)do})
|
128
127
|
assert_not_nil(match, "nonstandardpk table not found")
|
129
128
|
assert_match %r(primary_key: "movieid"), match[1], "non-standard primary key not preserved"
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
133
|
-
it
|
134
|
-
output = generate_schema_for_table
|
132
|
+
it "no id with model driven primary key" do
|
133
|
+
output = generate_schema_for_table "sst_no_pk_data"
|
135
134
|
_(output).must_match %r{create_table "sst_no_pk_data".*id:\sfalse.*do}
|
136
|
-
assert_line :name, type:
|
135
|
+
assert_line :name, type: "string", limit: nil, default: nil, collation: nil
|
137
136
|
end
|
138
137
|
|
139
|
-
|
140
138
|
private
|
141
139
|
|
142
140
|
def generate_schema_for_table(*table_names)
|
143
|
-
require
|
141
|
+
require "stringio"
|
144
142
|
stream = StringIO.new
|
145
143
|
ActiveRecord::SchemaDumper.ignore_tables = all_tables - table_names
|
146
144
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
|
@@ -150,6 +148,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
|
|
150
148
|
type_matcher = /\A\s+t\.\w+\s+"(.*?)"[,\n]/
|
151
149
|
@generated_schema.each_line do |line|
|
152
150
|
next unless line =~ type_matcher
|
151
|
+
|
153
152
|
@schema_lines[Regexp.last_match[1]] = SchemaLine.new(line)
|
154
153
|
end
|
155
154
|
@generated_schema
|
@@ -159,11 +158,12 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
|
|
159
158
|
@schema_lines[column_name.to_s]
|
160
159
|
end
|
161
160
|
|
162
|
-
def assert_line(column_name, options={})
|
161
|
+
def assert_line(column_name, options = {})
|
163
162
|
line = line(column_name)
|
164
163
|
assert line, "Count not find line with column name: #{column_name.inspect} in schema:\n#{schema}"
|
165
164
|
[:type, :limit, :precision, :scale, :collation, :default].each do |key|
|
166
165
|
next unless options.key?(key)
|
166
|
+
|
167
167
|
actual = key == :type ? line.send(:type_method) : line.send(key)
|
168
168
|
expected = options[key]
|
169
169
|
message = "#{key.to_s.titleize} of #{expected.inspect} not found in:\n#{line}"
|
@@ -182,7 +182,6 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
|
|
182
182
|
end
|
183
183
|
|
184
184
|
class SchemaLine
|
185
|
-
|
186
185
|
LINE_PARSER = %r{t\.(\w+)\s+"(.*?)"[,\s+](.*)}
|
187
186
|
|
188
187
|
attr_reader :line,
|
@@ -230,8 +229,5 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
|
|
230
229
|
rescue SyntaxError
|
231
230
|
{}
|
232
231
|
end
|
233
|
-
|
234
232
|
end
|
235
|
-
|
236
233
|
end
|
237
|
-
|