Class: MySQL::Search::CreateTriggerGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- MySQL::Search::CreateTriggerGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/mysql/search/create_trigger_generator.rb
Overview
This generator creates a migration to add a trigger for automatically updating the ‘updated_at` column in MySQL. It also includes a monkey-patch for ActiveRecord’s ‘#timestamps` method to use MySQL’s ‘DATETIME ON UPDATE CURRENT_TIMESTAMP` for the `updated_at` column.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(_path) ⇒ Object
15 16 17 |
# File 'lib/generators/mysql/search/create_trigger_generator.rb', line 15 def self.next_migration_number(_path) Time.now.utc.strftime('%Y%m%d%H%M%S') end |
Instance Method Details
#create_config_and_migration_files ⇒ Object
21 22 23 24 25 |
# File 'lib/generators/mysql/search/create_trigger_generator.rb', line 21 def create_config_and_migration_files migration_template 'db/migrate/enable_auto_update_of_updated_at.rb', 'db/migrate/enable_auto_update_of_updated_at.rb' template 'config/initializers/active_record_ext.rb' end |