Skip to content

Commit 1fc921c

Browse files
committed
Add smalldatetime type for migrations. Fixes #507
1 parent 83f6d57 commit 1fc921c

File tree

5 files changed

+9
-1
lines changed

5 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Performance w/inserts. Check binds & use schema cache for id inserts.
66
Fixes #572. Thanks @noelr.
7+
* Add smalldatetime type for migrations. Fixes #507
78

89
#### Changed
910

lib/active_record/connection_adapters/sqlserver/table_definition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def money(*args, **options)
2323
args.each { |name| column(name, :money, options) }
2424
end
2525

26+
def smalldatetime(*args, **options)
27+
args.each { |name| column(name, :smalldatetime, options) }
28+
end
29+
2630
def datetime(*args, **options)
2731
args.each do |name|
2832
if options[:precision]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def fast_string_to_time_format
1919
end
2020

2121
def apply_seconds_precision(value)
22-
value.change usec: 0
22+
value.change usec: 0 if value
2323
end
2424

2525
end

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
8585
# Our type methods.
8686
columns['real_col'].sql_type.must_equal 'real'
8787
columns['money_col'].sql_type.must_equal 'money'
88+
columns['smalldatetime_col'].sql_type.must_equal 'smalldatetime'
8889
columns['datetime2_col'].sql_type.must_equal 'datetime2(7)'
8990
columns['datetimeoffset'].sql_type.must_equal 'datetimeoffset(7)'
9091
columns['smallmoney_col'].sql_type.must_equal 'smallmoney'
@@ -100,6 +101,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
100101
columns['json_col'].sql_type.must_equal 'nvarchar(max)'
101102
assert_line :real_col, type: 'real', limit: nil, precision: nil, scale: nil, default: nil
102103
assert_line :money_col, type: 'money', limit: nil, precision: 19, scale: 4, default: nil
104+
assert_line :smalldatetime_col, type: 'smalldatetime', limit: nil, precision: nil, scale: nil, default: nil
103105
assert_line :datetime2_col, type: 'datetime', limit: nil, precision: 7, scale: nil, default: nil
104106
assert_line :datetimeoffset, type: 'datetimeoffset', limit: nil, precision: 7, scale: nil, default: nil
105107
assert_line :smallmoney_col, type: 'smallmoney', limit: nil, precision: 10, scale: 4, default: nil

test/schema/sqlserver_specific_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# Our type methods.
2222
t.real :real_col
2323
t.money :money_col
24+
t.smalldatetime :smalldatetime_col
2425
t.datetime2 :datetime2_col
2526
t.datetimeoffset :datetimeoffset
2627
t.smallmoney :smallmoney_col

0 commit comments

Comments
 (0)