Class: ActiveRecord::ConnectionAdapters::Mysql2GhostAdapter
- Inherits:
-
Mysql2Adapter
- Object
- Mysql2Adapter
- ActiveRecord::ConnectionAdapters::Mysql2GhostAdapter
- Defined in:
- lib/active_record/connection_adapters/mysql2_ghost_adapter.rb
Constant Summary collapse
- ADAPTER_NAME =
'mysql2_ghost'.freeze
Instance Method Summary collapse
- #add_index(table_name, column_name, options = {}) ⇒ Object
- #execute(sql, name = nil) ⇒ Object
-
#initialize(connection, logger, connection_options, config, dry_run: false) ⇒ Mysql2GhostAdapter
constructor
A new instance of Mysql2GhostAdapter.
- #remove_index(table_name, options = {}) ⇒ Object
Constructor Details
#initialize(connection, logger, connection_options, config, dry_run: false) ⇒ Mysql2GhostAdapter
Returns a new instance of Mysql2GhostAdapter.
39 40 41 42 43 |
# File 'lib/active_record/connection_adapters/mysql2_ghost_adapter.rb', line 39 def initialize(connection, logger, , config, dry_run: false) super(connection, logger, , config) @database = config[:database] @dry_run = dry_run end |
Instance Method Details
#add_index(table_name, column_name, options = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/active_record/connection_adapters/mysql2_ghost_adapter.rb', line 72 def add_index(table_name, column_name, **) index, algorithm, if_not_exists = (table_name, column_name, **) return if if_not_exists && index_exists?(table_name, column_name, name: index.name) index_type = index.type&.to_s&.upcase || (index.unique ? 'UNIQUE' : nil) sql = build_add_index_sql( table_name, quoted_columns(index), index.name, index_type: index_type, using: index.using, algorithm: algorithm ) execute sql end |
#execute(sql, name = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_record/connection_adapters/mysql2_ghost_adapter.rb', line 46 def execute(sql, name = nil, async: false) # Only ALTER TABLE statements are automatically skipped by gh-ost # We need to manually skip CREATE TABLE, DROP TABLE, and # INSERT/DELETE (to schema migrations) for dry runs return if dry_run && should_skip_for_dry_run?(sql) if (table, query = parse_sql(sql)) GhostAdapter::Migrator.execute(table, query, database, dry_run) else super(sql, name, async: async) end end |
#remove_index(table_name, options = {}) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/active_record/connection_adapters/mysql2_ghost_adapter.rb', line 88 def remove_index(table_name, column_name = nil, **) return if [:if_exists] && !index_exists?(table_name, column_name, **) index_name = index_name_for_remove(table_name, column_name, ) execute "ALTER TABLE #{quote_table_name(table_name)} DROP INDEX #{quote_column_name(index_name)}" end |