activerecord-sqlserver-adapter 5.0.3 → 5.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b2b6f7f8589a69b587c63d0de5713b527e2389f
4
- data.tar.gz: 738c33f3937b47b7e87b54bf6436fcc81d3dbd4f
3
+ metadata.gz: 9f171340d9c4e11e1baf5bfcdcc51c6de645f7c1
4
+ data.tar.gz: ef6051e74b57e8e5630993749d651a4be43c6f4e
5
5
  SHA512:
6
- metadata.gz: 65a7995a536eb3eedf3a771aff7c0645538189f131add85db6c585e43c03547ed64158009e53183310f05c8c9a5c40e8158baa79758f6bfcb0e5d7b680c472c5
7
- data.tar.gz: 69eae26ecb4a8ccb7cc61e8b689e579ecae2046692de4fefe9978f2e36c4e1731231aec33b580545a521245041f3af9b9f833ec2ee9160874acbe723e1421019
6
+ metadata.gz: 554f6f57cc679315c150b9fe1a624dfc7a58ccd0992c894bfbde6c8b6d487e1b6d0604d4d63048bd48994cfac62b07420a748fe8fdc9ca6b32e875895a58970a
7
+ data.tar.gz: d3e2d4fe42b20c3d6d6a25a39d6268d0c8f882669c88c3d8f1822d4a5c2ece0599a1d2806fdcdc48b5e79ed53b2d1556bb949c504377d8a3d35d253717e084b3
@@ -1,3 +1,11 @@
1
+ ## v5.0.4
2
+
3
+ #### Fixed
4
+
5
+ * Allow `datetimeoffset` to be used in migrations and represented in schema.
6
+ * Using transactions and resetting isolation level correctly when `READ_COMMITTED_SNAPSHOT` is set to `ON` Fixes #520
7
+
8
+
1
9
  ## v5.0.3
2
10
 
3
11
  #### Changed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.0.3
1
+ 5.0.4
@@ -14,7 +14,14 @@ module ActiveRecord
14
14
  def current_isolation_level
15
15
  return unless sqlserver?
16
16
  level = connection.user_options_isolation_level
17
- level.blank? ? 'READ COMMITTED' : level.upcase
17
+ # When READ_COMMITTED_SNAPSHOT is set to ON,
18
+ # user_options_isolation_level will be equal to 'read committed
19
+ # snapshot' which is not a valid isolation level
20
+ if level.blank? || level == 'read committed snapshot'
21
+ 'READ COMMITTED'
22
+ else
23
+ level.upcase
24
+ end
18
25
  end
19
26
 
20
27
  end
@@ -4,6 +4,10 @@ module ActiveRecord
4
4
  module Type
5
5
  class DateTimeOffset < DateTime2
6
6
 
7
+ def type
8
+ :datetimeoffset
9
+ end
10
+
7
11
  def sqlserver_type
8
12
  "datetimeoffset(#{precision.to_i})"
9
13
  end
@@ -417,7 +417,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
417
417
  skip 'datetimeoffset not supported in this protocal version' unless connection_dblib_73?
418
418
  col = column('datetimeoffset_7')
419
419
  col.sql_type.must_equal 'datetimeoffset(7)'
420
- col.type.must_equal :datetime
420
+ col.type.must_equal :datetimeoffset
421
421
  col.null.must_equal true
422
422
  col.default.must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
423
423
  obj.datetimeoffset_7.must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <999999900>"
@@ -434,20 +434,26 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
434
434
  obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
435
435
  obj.reload
436
436
  obj.datetimeoffset_7.must_equal Time.new(2010, 04, 01, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
437
+ # Maintains the timezone
438
+ time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456800, 1000)
439
+ obj.datetimeoffset_7 = time
440
+ obj.datetimeoffset_7.must_equal time
441
+ obj.save!
442
+ obj.datetimeoffset_7.must_equal time
443
+ obj.reload.datetimeoffset_7.must_equal time
437
444
  # With other precisions.
438
445
  time = ActiveSupport::TimeZone['America/Los_Angeles'].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
439
446
  col = column('datetimeoffset_3')
440
447
  connection.lookup_cast_type_from_column(col).precision.must_equal 3
441
448
  obj.datetimeoffset_3 = time
442
449
  obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
443
- # TODO: FreeTDS date bug fixed: https://github.com/FreeTDS/freetds/issues/44
444
- obj.save! ; obj.reload
450
+ obj.save!
445
451
  obj.datetimeoffset_3.must_equal time.change(nsec: 123000000), "Nanoseconds were <#{obj.datetimeoffset_3.nsec}> vs <123000000>"
446
452
  col = column('datetime2_1')
447
453
  connection.lookup_cast_type_from_column(col).precision.must_equal 1
448
454
  obj.datetime2_1 = time
449
455
  obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
450
- obj.save! ; obj.reload
456
+ obj.save!
451
457
  obj.datetime2_1.must_equal time.change(nsec: 100000000), "Nanoseconds were <#{obj.datetime2_1.nsec}> vs <100000000>"
452
458
  end
453
459
 
@@ -97,19 +97,20 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
97
97
  columns['varbinary_col'].sql_type.must_equal 'varbinary(8000)'
98
98
  columns['uuid_col'].sql_type.must_equal 'uniqueidentifier'
99
99
  columns['sstimestamp_col'].sql_type.must_equal 'timestamp'
100
- assert_line :real_col, type: 'real', limit: nil, precision: nil, scale: nil, default: nil
101
- assert_line :money_col, type: 'money', limit: nil, precision: 19, scale: 4, default: nil
102
- assert_line :datetime2_col, type: 'datetime', limit: nil, precision: 7, scale: nil, default: nil
103
- assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil
104
- assert_line :char_col, type: 'char', limit: 1, precision: nil, scale: nil, default: nil
105
- assert_line :varchar_col, type: 'varchar', limit: nil, precision: nil, scale: nil, default: nil
106
- assert_line :text_basic_col, type: 'text_basic', limit: 2147483647, precision: nil, scale: nil, default: nil
107
- assert_line :nchar_col, type: 'nchar', limit: 1, precision: nil, scale: nil, default: nil
108
- assert_line :ntext_col, type: 'ntext', limit: 2147483647, precision: nil, scale: nil, default: nil
109
- assert_line :binary_basic_col, type: 'binary_basic', limit: 1, precision: nil, scale: nil, default: nil
110
- assert_line :varbinary_col, type: 'varbinary', limit: nil, precision: nil, scale: nil, default: nil
111
- assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
112
- assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
100
+ assert_line :real_col, type: 'real', limit: nil, precision: nil, scale: nil, default: nil
101
+ assert_line :money_col, type: 'money', limit: nil, precision: 19, scale: 4, default: nil
102
+ assert_line :datetime2_col, type: 'datetime', limit: nil, precision: 7, scale: nil, default: nil
103
+ assert_line :datetimeoffset, type: 'datetimeoffset', limit: nil, precision: 7, scale: nil, default: nil
104
+ assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil
105
+ assert_line :char_col, type: 'char', limit: 1, precision: nil, scale: nil, default: nil
106
+ assert_line :varchar_col, type: 'varchar', limit: nil, precision: nil, scale: nil, default: nil
107
+ assert_line :text_basic_col, type: 'text_basic', limit: 2147483647, precision: nil, scale: nil, default: nil
108
+ assert_line :nchar_col, type: 'nchar', limit: 1, precision: nil, scale: nil, default: nil
109
+ assert_line :ntext_col, type: 'ntext', limit: 2147483647, precision: nil, scale: nil, default: nil
110
+ assert_line :binary_basic_col, type: 'binary_basic', limit: 1, precision: nil, scale: nil, default: nil
111
+ assert_line :varbinary_col, type: 'varbinary', limit: nil, precision: nil, scale: nil, default: nil
112
+ assert_line :uuid_col, type: 'uuid', limit: nil, precision: nil, scale: nil, default: nil
113
+ assert_line :sstimestamp_col, type: 'ss_timestamp', limit: nil, precision: nil, scale: nil, default: nil
113
114
  end
114
115
 
115
116
  # Special Cases
@@ -52,6 +52,31 @@ class TransactionTestSQLServer < ActiveRecord::TestCase
52
52
  connection.user_options_isolation_level.must_match %r{read committed}i
53
53
  end
54
54
 
55
+ describe 'when READ_COMMITTED_SNAPSHOT is set' do
56
+ before do
57
+ connection.execute "ALTER DATABASE [#{connection.current_database}] SET ALLOW_SNAPSHOT_ISOLATION ON"
58
+ connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE"
59
+ end
60
+
61
+ after do
62
+ connection.execute "ALTER DATABASE [#{connection.current_database}] SET ALLOW_SNAPSHOT_ISOLATION OFF"
63
+ connection.execute "ALTER DATABASE [#{connection.current_database}] SET READ_COMMITTED_SNAPSHOT OFF WITH ROLLBACK IMMEDIATE"
64
+ end
65
+
66
+ it 'should use READ COMMITTED as an isolation level' do
67
+ connection.user_options_isolation_level.must_match "read committed snapshot"
68
+
69
+ Ship.transaction(isolation: :serializable) do
70
+ Ship.create! name: 'Black Pearl'
71
+ end
72
+
73
+ # We're actually testing that the isolation level was correctly reset to
74
+ # "READ COMMITTED", and that no exception was raised (it's reported back
75
+ # by SQL Server as "read committed snapshot").
76
+ connection.user_options_isolation_level.must_match "read committed snapshot"
77
+ end
78
+ end
79
+
55
80
 
56
81
  protected
57
82
 
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: 5.0.3
4
+ version: 5.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2017-02-02 00:00:00.000000000 Z
17
+ date: 2017-02-16 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activerecord