Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for Existing but nil :precision Option #46140

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ def check_constraint(expression, **options)
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
Expand Down
17 changes: 17 additions & 0 deletions activerecord/test/cases/migration/compatibility_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ def migrate(x)
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)
Expand Down