From 64078e088650124b6c37ce6a3c352ad2dc4f072c Mon Sep 17 00:00:00 2001 From: Nikolay Kondratyev Date: Tue, 3 Jul 2018 12:17:40 +0500 Subject: Fix default value for mysql time types with specified precision The TIME, DATETIME, and TIMESTAMP types [have supported](https://mariadb.com/kb/en/library/microseconds-in-mariadb/) a fractional seconds precision from 0 to 6. Default values from time columns with specified precision is read as `current_timestamp(n)` from information schema. rake `db:schema:dump` produces `schema.rb` **without** default values for time columns with the specified precision: t.datetime "last_message_at", precision: 6, null: false rake `db:schema:dump` produces `schema.rb` **with** default values for time columns with the specified precision: t.datetime "last_message_at", precision: 6, default: -> { "current_timestamp(6)" }, null: false --- .../lib/active_record/connection_adapters/mysql/schema_statements.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb index ce50590651..2087938d7c 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb @@ -80,8 +80,8 @@ module ActiveRecord def new_column_from_field(table_name, field) type_metadata = fetch_type_metadata(field[:Type], field[:Extra]) - if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\(\))?\z/i.match?(field[:Default]) - default, default_function = nil, "CURRENT_TIMESTAMP" + if type_metadata.type == :datetime && /\ACURRENT_TIMESTAMP(?:\([0-6]?\))?\z/i.match?(field[:Default]) + default, default_function = nil, field[:Default] else default, default_function = field[:Default], nil end -- cgit v1.2.3