Sha256: 6d753375b8af8fef2174fed6a0f65af66983fc2faf1bbd53c394aa4b67a001bd

Contents?: true

Size: 650 Bytes

Versions: 6

Compression:

Stored size: 650 Bytes

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
audited-4.10.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-4.9.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-4.8.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-4.7.1 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-4.7.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb
audited-4.6.0 lib/generators/audited/templates/revert_polymorphic_indexes_order.rb