mirror of https://github.com/rails/rails
Merge pull request #46140 from ahoglund/ahoglund/nil-precision-option
Check for Existing but nil `:precision` Option
This commit is contained in:
commit
910af8f3c4
|
@ -514,6 +514,10 @@ module ActiveRecord
|
|||
def timestamps(**options)
|
||||
options[:null] = false if options[:null].nil?
|
||||
|
||||
if !options.key?(:precision) && @conn.supports_datetime_with_precision?
|
||||
options[:precision] = 6
|
||||
end
|
||||
|
||||
column(:created_at, :datetime, **options)
|
||||
column(:updated_at, :datetime, **options)
|
||||
end
|
||||
|
|
|
@ -274,6 +274,23 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def test_timestamps_sets_default_precision_on_create_table
|
||||
migration = Class.new(ActiveRecord::Migration[6.1]) {
|
||||
def migrate(x)
|
||||
create_table :more_testings do |t|
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
}.new
|
||||
|
||||
ActiveRecord::Migrator.new(:up, [migration], @schema_migration, @internal_metadata).migrate
|
||||
|
||||
assert connection.column_exists?(:more_testings, :created_at, **{ precision: 6 })
|
||||
assert connection.column_exists?(:more_testings, :updated_at, **{ precision: 6 })
|
||||
ensure
|
||||
connection.drop_table :more_testings rescue nil
|
||||
end
|
||||
|
||||
def test_datetime_doesnt_set_precision_on_create_table
|
||||
migration = Class.new(ActiveRecord::Migration[6.1]) {
|
||||
def migrate(x)
|
||||
|
|
Loading…
Reference in New Issue