Skip to content

Commit 8d1da5b

Browse files
authored
Fix Misc datetimeoffset Bugs (#559)
* Allow datetimeoffset to be represented in schema.rb. * CHANGELOG notes. [CI SKIP]
1 parent 3cee83c commit 8d1da5b

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v5.0.4
2+
3+
#### Fixed
4+
5+
* Allow `datetimeoffset` to be used in migrations and represented in schema.
6+
7+
18
## v5.0.3
29

310
#### Changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.3
1+
5.0.4

lib/active_record/connection_adapters/sqlserver/type/datetimeoffset.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ module SQLServer
44
module Type
55
class DateTimeOffset < DateTime2
66

7+
def type
8+
:datetimeoffset
9+
end
10+
711
def sqlserver_type
812
"datetimeoffset(#{precision.to_i})"
913
end

test/cases/column_test_sqlserver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def assert_obj_set_and_save(attribute, value)
417417
skip 'datetimeoffset not supported in this protocal version' unless connection_dblib_73?
418418
col = column('datetimeoffset_7')
419419
col.sql_type.must_equal 'datetimeoffset(7)'
420-
col.type.must_equal :datetime
420+
col.type.must_equal :datetimeoffset
421421
col.null.must_equal true
422422
col.default.must_equal Time.new(1984, 01, 24, 04, 20, 00, -28800).change(nsec: 123456700), "Nanoseconds <#{col.default.nsec}> vs <123456700>"
423423
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>"

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,20 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
9797
columns['varbinary_col'].sql_type.must_equal 'varbinary(8000)'
9898
columns['uuid_col'].sql_type.must_equal 'uniqueidentifier'
9999
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
113114
end
114115

115116
# Special Cases

0 commit comments

Comments
 (0)