Sha256: 613302540cbca6766f355319a98d851d8fde8387661a3f8efcf081833832bbce

Contents?: true

Size: 1.3 KB

Versions: 24

Compression:

Stored size: 1.3 KB

Contents

class CleanupIndexes < ActiveRecord::Migration
  def change
    # delete some leftovers in migrated CASino 1.x installations
    remove_deprecated_index_if_exists :login_tickets, [:ticket]
    remove_deprecated_index_if_exists :proxy_granting_tickets, [:granter_type, :granter_id]
    remove_deprecated_index_if_exists :proxy_granting_tickets, [:iou]
    remove_deprecated_index_if_exists :proxy_tickets, [:proxy_granting_ticket_id]
    remove_deprecated_index_if_exists :proxy_tickets, [:ticket]
    remove_deprecated_index_if_exists :service_rules, [:url]
    remove_deprecated_index_if_exists :service_tickets, [:ticket]
    remove_deprecated_index_if_exists :service_tickets, [:ticket_granting_ticket_id]
    remove_deprecated_index_if_exists :ticket_granting_tickets, [:ticket]
    remove_deprecated_index_if_exists :two_factor_authenticators, [:user_id]
    remove_deprecated_index_if_exists :users, [:authenticator, :username]
  end

  private
  def remove_deprecated_index_if_exists(old_table_name, column_names)
    table_name = :"casino_#{old_table_name}"
    index_name = :"index_#{old_table_name}_on_#{column_names.join('_and_')}"
    if index_name_exists?(table_name, index_name, false)
      remove_index table_name, name: index_name
    else
      puts "index #{index_name} on #{table_name} not found"
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
casino-4.1.2 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.1.1 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.1.0 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.3 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.2 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.1 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.0 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.0.pre.2 db/migrate/20131022110146_cleanup_indexes.rb
casino-4.0.0.pre.1 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.4 db/migrate/20131022110146_cleanup_indexes.rb
casino-2.0.7 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.3 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.2 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.1 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.0 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.0.pre.2 db/migrate/20131022110146_cleanup_indexes.rb
casino-3.0.0.pre.1 db/migrate/20131022110146_cleanup_indexes.rb
casino-2.0.6 db/migrate/20131022110146_cleanup_indexes.rb
casino-2.0.5 db/migrate/20131022110146_cleanup_indexes.rb
casino-2.0.4 db/migrate/20131022110146_cleanup_indexes.rb