Class: ActiveRecord::Migration::DefaultStrategy
- Inherits:
-
ExecutionStrategy
- Object
- ExecutionStrategy
- ActiveRecord::Migration::DefaultStrategy
- Defined in:
- activerecord/lib/active_record/migration/default_strategy.rb
Overview
Default Strategy
DefaultStrategy is the default execution strategy for migrations. It delegates all method calls directly to the connection adapter, which is the standard behavior for executing migration commands.
This class is the recommended base class for custom migration strategies. By inheriting from DefaultStrategy, you can override specific methods while retaining the default behavior for all other migration operations.
Example: Creating a Custom Strategy
class AuditingStrategy < ActiveRecord::Migration::DefaultStrategy
def create_table(table_name, **)
Rails.logger.info "Creating table: #{table_name}"
super
end
def drop_table(table_name, **)
Rails.logger.warn "Dropping table: #{table_name}"
super
end
end
# Apply globally
config.active_record.migration_strategy = AuditingStrategy
# Or apply to a specific adapter
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.migration_strategy = AuditingStrategy
Available Methods
DefaultStrategy responds to all methods available on the connection adapter, including but not limited to:
-
create_table -
drop_table -
add_column -
remove_column -
add_index -
remove_index -
add_foreign_key -
remove_foreign_key -
execute
See ActiveRecord::ConnectionAdapters::SchemaStatements for the complete list of available schema modification methods.
Method Summary
Methods inherited from ExecutionStrategy
Constructor Details
This class inherits a constructor from ActiveRecord::Migration::ExecutionStrategy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object (private)
54 55 56 |
# File 'activerecord/lib/active_record/migration/default_strategy.rb', line 54 def method_missing(method, ...) connection.send(method, ...) end |