Sha256: 2037e744efde28acfd0e4aa46af931476f523d2652811da567be62c9b0741cb5

Contents?: true

Size: 817 Bytes

Versions: 9

Compression:

Stored size: 817 Bytes

Contents

require "vanity/adapters/active_record_adapter"

class AddParticipantsUniqueIndexMigration < 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_participants, :name => "by_experiment_id_and_identity"
      add_index :vanity_participants, [:experiment_id, :identity], :name => "by_experiment_id_and_identity", :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_participants_unique_index_migration.rb.erb
vanity-4.0.3 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-4.0.2 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-4.0.1 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-4.0.0 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-3.1.0 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-3.0.2 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-3.0.1 lib/generators/templates/add_participants_unique_index_migration.rb.erb
vanity-3.0.0 lib/generators/templates/add_participants_unique_index_migration.rb.erb