Sha256: 231dd07cb96dea18c3e0a8cc9333cfc883a015984cedd52e661586c99ee0b612

Contents?: true

Size: 1.07 KB

Versions: 47

Compression:

Stored size: 1.07 KB

Contents

require 'switchman/sharded_instrumenter'

module Switchman
  module ActiveRecord
    module AbstractAdapter
      module ForeignKeyCheck
        def add_column(table, name, type, options = {})
          Engine.foreign_key_check(name, type, options)
          super
        end
      end

      attr_writer :shard
      attr_reader :last_query_at

      def shard
        @shard || Shard.default
      end

      def initialize(*args)
        super
        @instrumenter = Switchman::ShardedInstrumenter.new(@instrumenter, self)
        @last_query_at = Time.now
      end

      def quote_local_table_name(name)
        quote_table_name(name)
      end

      def use_qualified_names?
        false
      end

      protected

      def log(*args, &block)
        super
      ensure
        @last_query_at = Time.now
      end

      private

      def id_value_for_database(value)
        return super unless value.class.sharded_primary_key?
        # do this the Rails 4.2 way, so that if Shard.current != self.shard, the id gets transposed
        quote(value.id)
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
switchman-1.11.3 lib/switchman/active_record/abstract_adapter.rb
switchman-1.10.3 lib/switchman/active_record/abstract_adapter.rb
switchman-1.11.2 lib/switchman/active_record/abstract_adapter.rb
switchman-1.11.1 lib/switchman/active_record/abstract_adapter.rb
switchman-1.10.2 lib/switchman/active_record/abstract_adapter.rb
switchman-1.10.1 lib/switchman/active_record/abstract_adapter.rb
switchman-1.10.0 lib/switchman/active_record/abstract_adapter.rb