Sha256: 1ba5ab6390faa8ae348021036f00d24bec2ae3746d2d35eff3b391c75ef717a6

Contents?: true

Size: 681 Bytes

Versions: 25

Compression:

Stored size: 681 Bytes

Contents

# frozen_string_literal: true

class <%= migration_class_name %> < <%= migration_parent %>
  def self.up
    fix_index_order_for [:associated_id, :associated_type], 'associated_index'
    fix_index_order_for [:auditable_id, :auditable_type], 'auditable_index'
  end

  def self.down
    fix_index_order_for [:associated_type, :associated_id], 'associated_index'
    fix_index_order_for [:auditable_type, :auditable_id], 'auditable_index'
  end

  private

  def fix_index_order_for(columns, index_name)
    if index_exists? :audits, columns, name: index_name
      remove_index :audits, name: index_name
      add_index :audits, columns.reverse, name: index_name
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
audited-5.8.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.7.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.6.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.5.1.pre lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.5.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.4.3 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.4.2 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.4.1 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.4.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.3.3 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.3.2 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.3.1 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.3.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.2.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-5.1.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
velocity_audited-6.0.4 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
velocity_audited-6.0.3 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
velocity_audited-6.0.1 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
velocity_audited-5.1.6 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
velocity_audited-5.1.5 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb