mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't attempt to specify datetime precision unless supported
Specifically, versions of MySQL prior to 5.6 do not support this, which is what's used on Travis by default. The method `mysql_56?` appeared to only ever be used to conditionally apply subsecond precision, so I've generalized it and used it more liberally. This should fix the test failures caused by #20317
This commit is contained in:
parent
66337b62ad
commit
f696494aed
3 changed files with 32 additions and 13 deletions
|
@ -204,7 +204,7 @@ class BasicsTest < ActiveRecord::TestCase
|
|||
)
|
||||
|
||||
# For adapters which support microsecond resolution.
|
||||
if current_adapter?(:PostgreSQLAdapter, :SQLite3Adapter) || mysql_56?
|
||||
if subsecond_precision_supported?
|
||||
assert_equal 11, Topic.find(1).written_on.sec
|
||||
assert_equal 223300, Topic.find(1).written_on.usec
|
||||
assert_equal 9900, Topic.find(2).written_on.usec
|
||||
|
|
|
@ -46,10 +46,10 @@ def in_memory_db?
|
|||
ActiveRecord::Base.connection_pool.spec.config[:database] == ":memory:"
|
||||
end
|
||||
|
||||
def mysql_56?
|
||||
current_adapter?(:MysqlAdapter, :Mysql2Adapter) &&
|
||||
ActiveRecord::Base.connection.send(:version) >= '5.6.0' &&
|
||||
ActiveRecord::Base.connection.send(:version) < '5.7.0'
|
||||
def subsecond_precision_supported?
|
||||
!current_adapter?(:MysqlAdapter, :Mysql2Adapter) ||
|
||||
(ActiveRecord::Base.connection.send(:version) >= '5.6.0' &&
|
||||
ActiveRecord::Base.connection.send(:version) < '5.7.0')
|
||||
end
|
||||
|
||||
def mysql_enforcing_gtid_consistency?
|
||||
|
|
|
@ -251,10 +251,17 @@ ActiveRecord::Schema.define do
|
|||
create_table :developers, force: true do |t|
|
||||
t.string :name
|
||||
t.integer :salary, default: 70000
|
||||
if subsecond_precision_supported?
|
||||
t.datetime :created_at, precision: 6
|
||||
t.datetime :updated_at, precision: 6
|
||||
t.datetime :created_on, precision: 6
|
||||
t.datetime :updated_on, precision: 6
|
||||
else
|
||||
t.datetime :created_at
|
||||
t.datetime :updated_at
|
||||
t.datetime :created_on
|
||||
t.datetime :updated_on
|
||||
end
|
||||
end
|
||||
|
||||
create_table :developers_projects, force: true, id: false do |t|
|
||||
|
@ -353,7 +360,11 @@ ActiveRecord::Schema.define do
|
|||
|
||||
create_table :invoices, force: true do |t|
|
||||
t.integer :balance
|
||||
if subsecond_precision_supported?
|
||||
t.datetime :updated_at, precision: 6
|
||||
else
|
||||
t.datetime :updated_at
|
||||
end
|
||||
end
|
||||
|
||||
create_table :iris, force: true do |t|
|
||||
|
@ -503,7 +514,11 @@ ActiveRecord::Schema.define do
|
|||
|
||||
create_table :owners, primary_key: :owner_id, force: true do |t|
|
||||
t.string :name
|
||||
if subsecond_precision_supported?
|
||||
t.column :updated_at, :datetime, precision: 6
|
||||
else
|
||||
t.column :updated_at, :datetime
|
||||
end
|
||||
t.column :happy_at, :datetime
|
||||
t.string :essay_id
|
||||
end
|
||||
|
@ -755,7 +770,7 @@ ActiveRecord::Schema.define do
|
|||
t.string :title, limit: 250
|
||||
t.string :author_name
|
||||
t.string :author_email_address
|
||||
if mysql_56?
|
||||
if subsecond_precision_supported?
|
||||
t.datetime :written_on, precision: 6
|
||||
else
|
||||
t.datetime :written_on
|
||||
|
@ -778,7 +793,11 @@ ActiveRecord::Schema.define do
|
|||
t.string :parent_title
|
||||
t.string :type
|
||||
t.string :group
|
||||
if subsecond_precision_supported?
|
||||
t.timestamps null: true, precision: 6
|
||||
else
|
||||
t.timestamps null: true
|
||||
end
|
||||
end
|
||||
|
||||
create_table :toys, primary_key: :toy_id, force: true do |t|
|
||||
|
|
Loading…
Reference in a new issue