mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Dump datetime precision always in MySQL
This commit is contained in:
parent
3c801e7b26
commit
3432d6b03e
4 changed files with 6 additions and 10 deletions
|
@ -53,9 +53,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def schema_precision(column)
|
||||
return if /\Adatetime\b/.match(column.sql_type) && column.precision == 6
|
||||
return if /\Atime(?:stamp)?\b/.match?(column.sql_type) && column.precision == 0
|
||||
super
|
||||
super unless /\Atime(?:stamp)?\b/.match?(column.sql_type) && column.precision == 0
|
||||
end
|
||||
|
||||
def schema_collation(column)
|
||||
|
|
|
@ -193,15 +193,13 @@ if supports_datetime_with_precision?
|
|||
end
|
||||
end
|
||||
|
||||
def test_schema_dump_includes_non_default_datetime_precision
|
||||
def test_schema_dump_includes_datetime_precision
|
||||
@connection.create_table(:foos, force: true) do |t|
|
||||
t.datetime :datetime_zero, precision: 0
|
||||
t.timestamps precision: 6
|
||||
end
|
||||
output = dump_table_schema("foos")
|
||||
assert_match %r{t\.datetime\s+"datetime_zero",\s+precision: 0$}, output
|
||||
assert_match %r{t\.datetime\s+"created_at",\s+null: false$}, output
|
||||
assert_match %r{t\.datetime\s+"updated_at",\s+null: false$}, output
|
||||
assert_match %r{t\.datetime\s+"created_at",\s+precision: 6,\s+null: false$}, output
|
||||
assert_match %r{t\.datetime\s+"updated_at",\s+precision: 6,\s+null: false$}, output
|
||||
end
|
||||
|
||||
if current_adapter?(:PostgreSQLAdapter, :SQLServerAdapter)
|
||||
|
|
|
@ -321,7 +321,7 @@ class PrimaryKeyAnyTypeTest < ActiveRecord::TestCase
|
|||
test "schema typed primary key column" do
|
||||
@connection.create_table(:scheduled_logs, id: :timestamp, precision: 6, force: true)
|
||||
schema = dump_table_schema("scheduled_logs")
|
||||
assert_match %r/create_table "scheduled_logs", id: { type: :timestamp.* }/, schema
|
||||
assert_match %r/create_table "scheduled_logs", id: { type: :timestamp, precision: 6.* }/, schema
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -840,7 +840,7 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
|
|||
assert_match %r{t\.date\s+"date_with_default",\s+default: "2014-06-05"}, output
|
||||
|
||||
if supports_datetime_with_precision?
|
||||
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: "2014-06-05 07:17:04"}, output
|
||||
assert_match %r{t\.datetime\s+"datetime_with_default",\s+precision: 6,\s+default: "2014-06-05 07:17:04"}, output
|
||||
else
|
||||
assert_match %r{t\.datetime\s+"datetime_with_default",\s+default: "2014-06-05 07:17:04"}, output
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue