Module: ActiveRecord::ConnectionAdapters::SchemaStatements

Defined in:
lib/generators/mysql/search/templates/config/initializers/active_record_ext.rb

Overview

Overrides the default ‘add_timestamps` method to use MySQL’s ‘DATETIME ON UPDATE CURRENT_TIMESTAMP` for the `updated_at` column. This allows the `updated_at` column to automatically update its value whenever the row is updated.

Instance Method Summary collapse

Instance Method Details

#add_timestamps(table_name, **options) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/generators/mysql/search/templates/config/initializers/active_record_ext.rb', line 9

def add_timestamps(table_name, **options)
  options[:null] = false if options[:null].nil?

  options[:precision] = 6 if !options.key?(:precision) && supports_datetime_with_precision?

  add_column table_name, :created_at, :datetime, **options
  add_column table_name, :updated_at, 'DATETIME ON UPDATE CURRENT_TIMESTAMP', **options
end