Sha256: 4c389b604a980fe6a7e033cf4dee5793e46b081976fdc5a929c74a6ee03be2f0

Contents?: true

Size: 970 Bytes

Versions: 17

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

class MultiSchema
  def active?
    ENV['DATABASE'] == 'postgresql'
  end

  def create(schema_name)
    return unless active?

    unless connection.schema_exists? schema_name
      connection.execute %Q{CREATE SCHEMA "#{schema_name}"}
    end

    switch schema_name
    load Rails.root.join('db', 'schema.rb')
  end

  def current
    connection.schema_search_path
  end

  def switch(schema_name)
    connection.schema_search_path = %Q{"#{schema_name}"}
    connection.clear_query_cache
  end

  private

  def connection
    ActiveRecord::Base.connection
  end

  class IndexSet < ThinkingSphinx::IndexSet
    private

    def indices
      return super if index_names.any?

      prefixed = !multi_schema.current.include?('public')
      super.select { |index|
        prefixed ? index.name[/_two_core$/] : index.name[/_two_core$/].nil?
      }
    end

    def multi_schema
      @multi_schema ||= MultiSchema.new
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/support/multi_schema.rb
thinking-sphinx-5.5.1 spec/support/multi_schema.rb
thinking-sphinx-5.5.0 spec/support/multi_schema.rb
thinking-sphinx-5.4.0 spec/support/multi_schema.rb
thinking-sphinx-5.3.0 spec/support/multi_schema.rb
thinking-sphinx-5.2.1 spec/support/multi_schema.rb
thinking-sphinx-5.2.0 spec/support/multi_schema.rb
thinking-sphinx-5.1.0 spec/support/multi_schema.rb
thinking-sphinx-5.0.0 spec/support/multi_schema.rb
thinking-sphinx-4.4.1 spec/support/multi_schema.rb
thinking-sphinx-4.4.0 spec/support/multi_schema.rb
thinking-sphinx-4.3.2 spec/support/multi_schema.rb
thinking-sphinx-4.3.1 spec/support/multi_schema.rb
thinking-sphinx-4.3.0 spec/support/multi_schema.rb
thinking-sphinx-4.2.0 spec/support/multi_schema.rb
thinking-sphinx-4.1.0 spec/support/multi_schema.rb
thinking-sphinx-4.0.0 spec/support/multi_schema.rb