activerecord-sqlserver-adapter 7.1.0 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +20 -0
- data/test/cases/active_schema_test_sqlserver.rb +98 -26
- data/test/cases/coerced_tests.rb +3 -0
- data/test/cases/column_test_sqlserver.rb +4 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670622c4f84954789b5050d84bbe47ce3235a614bcd12a083716d9c2c8b775c7
|
4
|
+
data.tar.gz: 07720ea291eabf91fbb2def06c493a423795533a08394a2837faff4825ef660a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0144e10d2f2670cf7ab24fc9e5ca50351474b09e82a8d2322a4a402ce5d3365e697f487db5741b9b8199afbe68319093d7c14cd3fbfecce49f041d8b3ee295d7
|
7
|
+
data.tar.gz: c4d3666c0f01d14e7985651cbd7fd40da9e5bfb03e509e53a5709fe0fcd956efff3d01bdb7a97c12037c80a1588c8afa34e1eaad11623341ba748cff9195e112
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## v7.1.1
|
2
|
+
|
3
|
+
#### Fixed
|
4
|
+
|
5
|
+
- [#1145](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1145) Ensure correct order of COLLATE and NOT NULL in CREATE TABLE statements
|
6
|
+
- [#1144](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1144) Fix precision handling in time migration
|
7
|
+
- [#1143](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1143) Fix precision handling for datetimeoffset migration
|
8
|
+
|
1
9
|
## v7.1.0
|
2
10
|
|
3
11
|
#### Added
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ Interested in older versions? We follow a rational versioning policy that tracks
|
|
13
13
|
|
14
14
|
| Adapter Version | Rails Version | Support | Branch |
|
15
15
|
|-----------------|---------------|---------|--------------------------------------------------------------------------------------------------|
|
16
|
-
| `7.1.
|
16
|
+
| `7.1.1` | `7.1.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
|
17
17
|
| `7.0.5.1` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
|
18
18
|
| `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
|
19
19
|
| `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
|
@@ -100,7 +100,7 @@ module ActiveRecord
|
|
100
100
|
class SQLServerAdapter < AbstractAdapter
|
101
101
|
def configure_connection
|
102
102
|
super
|
103
|
-
|
103
|
+
@raw_connection.execute("SET TEXTSIZE #{64.megabytes}").do
|
104
104
|
end
|
105
105
|
end
|
106
106
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.1.
|
1
|
+
7.1.1
|
@@ -51,12 +51,12 @@ module ActiveRecord
|
|
51
51
|
|
52
52
|
def add_column_options!(sql, options)
|
53
53
|
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
|
54
|
-
if options[:null] == false
|
55
|
-
sql << " NOT NULL"
|
56
|
-
end
|
57
54
|
if options[:collation].present?
|
58
55
|
sql << " COLLATE #{options[:collation]}"
|
59
56
|
end
|
57
|
+
if options[:null] == false
|
58
|
+
sql << " NOT NULL"
|
59
|
+
end
|
60
60
|
if options[:is_identity] == true
|
61
61
|
sql << " IDENTITY(1,1)"
|
62
62
|
end
|
@@ -303,6 +303,16 @@ module ActiveRecord
|
|
303
303
|
when 5..8 then "bigint"
|
304
304
|
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
|
305
305
|
end
|
306
|
+
when "time" # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql
|
307
|
+
column_type_sql = type.to_s
|
308
|
+
if precision
|
309
|
+
if (0..7) === precision
|
310
|
+
column_type_sql << "(#{precision})"
|
311
|
+
else
|
312
|
+
raise(ActiveRecordError, "The time type has precision of #{precision}. The allowed range of precision is from 0 to 7")
|
313
|
+
end
|
314
|
+
end
|
315
|
+
column_type_sql
|
306
316
|
when "datetime2"
|
307
317
|
column_type_sql = super
|
308
318
|
if precision
|
@@ -313,6 +323,16 @@ module ActiveRecord
|
|
313
323
|
end
|
314
324
|
end
|
315
325
|
column_type_sql
|
326
|
+
when "datetimeoffset"
|
327
|
+
column_type_sql = super
|
328
|
+
if precision
|
329
|
+
if (0..7) === precision
|
330
|
+
column_type_sql << "(#{precision})"
|
331
|
+
else
|
332
|
+
raise(ActiveRecordError, "The datetimeoffset type has precision of #{precision}. The allowed range of precision is from 0 to 7")
|
333
|
+
end
|
334
|
+
end
|
335
|
+
column_type_sql
|
316
336
|
else
|
317
337
|
super
|
318
338
|
end
|
@@ -3,43 +3,43 @@
|
|
3
3
|
require "cases/helper_sqlserver"
|
4
4
|
|
5
5
|
class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe "indexes" do
|
7
|
+
before do
|
8
|
+
connection.create_table :schema_test_table, force: true, id: false do |t|
|
9
|
+
t.column :foo, :string, limit: 100
|
10
|
+
t.column :state, :string
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
after do
|
15
|
+
connection.drop_table :schema_test_table rescue nil
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
it 'default index' do
|
19
|
+
assert_sql('CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
20
|
+
connection.add_index :schema_test_table, "foo"
|
21
|
+
end
|
20
22
|
end
|
21
|
-
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
it 'unique index' do
|
25
|
+
assert_sql('CREATE UNIQUE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
26
|
+
connection.add_index :schema_test_table, "foo", unique: true
|
27
|
+
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
it 'where condition on index' do
|
31
|
+
assert_sql("CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo]) WHERE state = 'active'") do
|
32
|
+
connection.add_index :schema_test_table, "foo", where: "state = 'active'"
|
33
|
+
end
|
32
34
|
end
|
33
|
-
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it 'if index does not exist' do
|
37
|
+
assert_sql("IF NOT EXISTS (SELECT name FROM sysindexes WHERE name = 'index_schema_test_table_on_foo') " \
|
38
|
+
"CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])") do
|
39
|
+
connection.add_index :schema_test_table, "foo", if_not_exists: true
|
40
|
+
end
|
39
41
|
end
|
40
|
-
end
|
41
42
|
|
42
|
-
describe "index types" do
|
43
43
|
it 'clustered index' do
|
44
44
|
assert_sql('CREATE CLUSTERED INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
45
45
|
connection.add_index :schema_test_table, "foo", type: :clustered
|
@@ -52,4 +52,76 @@ class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
|
+
|
56
|
+
describe 'collation' do
|
57
|
+
it "create column with NOT NULL and COLLATE" do
|
58
|
+
assert_nothing_raised do
|
59
|
+
connection.create_table :not_null_with_collation_table, force: true, id: false do |t|
|
60
|
+
t.text :not_null_text_with_collation, null: false, collation: "Latin1_General_CS_AS"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
ensure
|
64
|
+
connection.drop_table :not_null_with_collation_table rescue nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'datetimeoffset precision' do
|
69
|
+
it 'valid precisions are correct' do
|
70
|
+
assert_nothing_raised do
|
71
|
+
connection.create_table :datetimeoffset_precisions do |t|
|
72
|
+
t.datetimeoffset :precision_default
|
73
|
+
t.datetimeoffset :precision_5, precision: 5
|
74
|
+
t.datetimeoffset :precision_7, precision: 7
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
columns = connection.columns("datetimeoffset_precisions")
|
79
|
+
|
80
|
+
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
|
81
|
+
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
|
82
|
+
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
|
83
|
+
ensure
|
84
|
+
connection.drop_table :datetimeoffset_precisions rescue nil
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'invalid precision raises exception' do
|
88
|
+
assert_raise(ActiveRecord::ActiveRecordError) do
|
89
|
+
connection.create_table :datetimeoffset_precisions do |t|
|
90
|
+
t.datetimeoffset :precision_8, precision: 8
|
91
|
+
end
|
92
|
+
end
|
93
|
+
ensure
|
94
|
+
connection.drop_table :datetimeoffset_precisions rescue nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'time precision' do
|
99
|
+
it 'valid precisions are correct' do
|
100
|
+
assert_nothing_raised do
|
101
|
+
connection.create_table :time_precisions do |t|
|
102
|
+
t.time :precision_default
|
103
|
+
t.time :precision_5, precision: 5
|
104
|
+
t.time :precision_7, precision: 7
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
columns = connection.columns("time_precisions")
|
109
|
+
|
110
|
+
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
|
111
|
+
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
|
112
|
+
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
|
113
|
+
ensure
|
114
|
+
connection.drop_table :time_precisions rescue nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'invalid precision raises exception' do
|
118
|
+
assert_raise(ActiveRecord::ActiveRecordError) do
|
119
|
+
connection.create_table :time_precisions do |t|
|
120
|
+
t.time :precision_8, precision: 8
|
121
|
+
end
|
122
|
+
end
|
123
|
+
ensure
|
124
|
+
connection.drop_table :time_precisions rescue nil
|
125
|
+
end
|
126
|
+
end
|
55
127
|
end
|
data/test/cases/coerced_tests.rb
CHANGED
@@ -1832,6 +1832,9 @@ class TimePrecisionTest < ActiveRecord::TestCase
|
|
1832
1832
|
|
1833
1833
|
# SQL Server uses default precision for time.
|
1834
1834
|
coerce_tests! :test_no_time_precision_isnt_truncated_on_assignment
|
1835
|
+
|
1836
|
+
# SQL Server accepts precision of 7 for time.
|
1837
|
+
coerce_tests! :test_invalid_time_precision_raises_error
|
1835
1838
|
end
|
1836
1839
|
|
1837
1840
|
class DefaultNumbersTest < ActiveRecord::TestCase
|
@@ -435,13 +435,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
435
435
|
_(type.limit).must_be_nil
|
436
436
|
_(type.precision).must_equal 7
|
437
437
|
_(type.scale).must_be_nil
|
438
|
-
|
438
|
+
|
439
|
+
# Can save 100 nanosecond precisions and return again.
|
439
440
|
obj.datetimeoffset_7 = Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456755)
|
440
441
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
441
442
|
obj.save!
|
442
443
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
443
444
|
obj.reload
|
444
445
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
446
|
+
|
445
447
|
# Maintains the timezone
|
446
448
|
time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456800, 1000)
|
447
449
|
obj.datetimeoffset_7 = time
|
@@ -449,6 +451,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
449
451
|
obj.save!
|
450
452
|
_(obj.datetimeoffset_7).must_equal time
|
451
453
|
_(obj.reload.datetimeoffset_7).must_equal time
|
454
|
+
|
452
455
|
# With other precisions.
|
453
456
|
time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
454
457
|
col = column("datetimeoffset_3")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-sqlserver-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.1.
|
4
|
+
version: 7.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
|
-
date:
|
18
|
+
date: 2024-01-08 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -235,8 +235,8 @@ licenses:
|
|
235
235
|
- MIT
|
236
236
|
metadata:
|
237
237
|
bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
|
238
|
-
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.
|
239
|
-
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.
|
238
|
+
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.1/CHANGELOG.md
|
239
|
+
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.1
|
240
240
|
post_install_message:
|
241
241
|
rdoc_options: []
|
242
242
|
require_paths:
|