Skip to content

Commit 8a7aa8e

Browse files
committed
datetime without precision now has default of 6
1 parent 62d0414 commit 8a7aa8e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

test/cases/coerced_tests.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,34 @@ def test_create_table_with_defaults_coerce
542542
assert_equal 1, four.default
543543
assert_equal "hello", five.default
544544
end
545+
546+
# Rails adds precision 6 by default, sql server uses datetime2 for datetimes with precision
547+
coerce_tests! :test_add_column_with_postgresql_datetime_type
548+
def test_add_column_with_postgresql_datetime_type_coerced
549+
connection.create_table :testings do |t|
550+
t.column :foo, :datetime
551+
end
552+
553+
column = connection.columns(:testings).find { |c| c.name == "foo" }
554+
555+
assert_equal :datetime, column.type
556+
assert_equal "datetime2(6)", column.sql_type
557+
end
558+
559+
# timestamp is datetime with default limit
560+
coerce_tests! :test_change_column_with_timestamp_type
561+
def test_change_column_with_timestamp_type_coerced
562+
connection.create_table :testings do |t|
563+
t.column :foo, :datetime, null: false
564+
end
565+
566+
connection.change_column :testings, :foo, :timestamp
567+
568+
column = connection.columns(:testings).find { |c| c.name == "foo" }
569+
570+
assert_equal :datetime, column.type
571+
assert_equal "datetime", column.sql_type
572+
end
545573
end
546574
end
547575
end

test/cases/schema_dumper_test_sqlserver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
6767
_(columns["float_col"].sql_type).must_equal "float"
6868
_(columns["string_col"].sql_type).must_equal "nvarchar(4000)"
6969
_(columns["text_col"].sql_type).must_equal "nvarchar(max)"
70-
_(columns["datetime_col"].sql_type).must_equal "datetime"
70+
_(columns["datetime_col"].sql_type).must_equal "datetime2(6)"
7171
_(columns["timestamp_col"].sql_type).must_equal "datetime"
7272
_(columns["time_col"].sql_type).must_equal "time(7)"
7373
_(columns["date_col"].sql_type).must_equal "date"
@@ -79,7 +79,7 @@ class SchemaDumperTestSQLServer < ActiveRecord::TestCase
7979
assert_line :float_col, type: "float", limit: nil, precision: nil, scale: nil, default: nil
8080
assert_line :string_col, type: "string", limit: nil, precision: nil, scale: nil, default: nil
8181
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
82+
assert_line :datetime_col, type: "datetime", limit: nil, precision: 6, scale: nil, default: nil
8383
assert_line :timestamp_col, type: "datetime", limit: nil, precision: nil, scale: nil, default: nil
8484
assert_line :time_col, type: "time", limit: nil, precision: 7, scale: nil, default: nil
8585
assert_line :date_col, type: "date", limit: nil, precision: nil, scale: nil, default: nil

0 commit comments

Comments
 (0)