Sha256: 3eb7383a7c2f8ea12f9c6efe4cba11cb8d0cc46010d25de15e2dbbe80eb91be6

Contents?: true

Size: 965 Bytes

Versions: 9

Compression:

Stored size: 965 Bytes

Contents

require "vanity/adapters/active_record_adapter"

class AddVanityUniqueIndexes < ActiveRecord::Migration<%= migration_version %>
  # Helper methods to ensure we're connecting to the right database, see
  # https://github.com/assaf/vanity/issues/295.

  def connection
    @connection ||= ActiveRecord::Base.connection
  end
  alias_method :default_connection, :connection

  def with_vanity_connection
    @connection = Vanity::Adapters::ActiveRecordAdapter::VanityRecord.connection
    yield
    @connection = default_connection
  end

  def change
    with_vanity_connection do
      remove_index :vanity_experiments, [:experiment_id]
      add_index :vanity_experiments, [:experiment_id], :unique => true

      remove_index :vanity_conversions, :name => "by_experiment_id_and_alternative", :unique => true
      add_index :vanity_conversions, [:vanity_experiment_id, :alternative], :name => "by_experiment_id_and_alternative", :unique => true
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vanity-4.0.4 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-4.0.3 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-4.0.2 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-4.0.1 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-4.0.0 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-3.1.0 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-3.0.2 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-3.0.1 lib/generators/templates/add_unique_indexes_migration.rb.erb
vanity-3.0.0 lib/generators/templates/add_unique_indexes_migration.rb.erb