Sha256: f4ff9e477ebb0239efaed6141523c19c3848ee8c002f649cd2d620730fd028e5

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

module SchemaMonkey::CoreExtensions
  module ActiveRecord
    module ConnectionAdapters
      module Mysql2Adapter

        def self.included(base)
          base.class_eval do
            alias_method_chain :indexes, :schema_monkey
            alias_method_chain :tables, :schema_monkey
          end
          SchemaMonkey.include_once ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter, SchemaMonkey::CoreExtensions::ActiveRecord::ConnectionAdapters::SchemaStatements::Column
          SchemaMonkey.include_once ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter, SchemaMonkey::CoreExtensions::ActiveRecord::ConnectionAdapters::SchemaStatements::Reference
          SchemaMonkey.include_once ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter, SchemaMonkey::CoreExtensions::ActiveRecord::ConnectionAdapters::SchemaStatements::Index
        end

        def indexes_with_schema_monkey(table_name, query_name=nil)
          SchemaMonkey::Middleware::Query::Indexes.start(connection: self, table_name: table_name, query_name: query_name, index_definitions: []) { |env|
            env.index_definitions += indexes_without_schema_monkey env.table_name, env.query_name
          }.index_definitions
        end

        def tables_with_schema_monkey(query_name=nil, database=nil, like=nil)
          SchemaMonkey::Middleware::Query::Tables.start(connection: self, query_name: query_name, database: database, like: like, tables: []) { |env|
            env.tables += tables_without_schema_monkey env.query_name, env.database, env.like
          }.tables
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schema_monkey-1.0.1 lib/schema_monkey/core_extensions/active_record/connection_adapters/mysql2_adapter.rb
schema_monkey-1.0.0 lib/schema_monkey/core_extensions/active_record/connection_adapters/mysql2_adapter.rb