Sha256: cfd71683b896ab096f53344c50f7a559c629392513e9ff34a8e980b2545672c4

Contents?: true

Size: 852 Bytes

Versions: 42

Compression:

Stored size: 852 Bytes

Contents

class <%= migration_class_name %> < ActiveRecord::Migration
  def self.up
    if index_exists? :audits, [:association_id, :association_type], :name => 'association_index'
      remove_index :audits, :name => 'association_index'
    end

    rename_column :audits, :association_id, :associated_id
    rename_column :audits, :association_type, :associated_type

    add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
  end

  def self.down
    if index_exists? :audits, [:associated_id, :associated_type], :name => 'associated_index'
      remove_index :audits, :name => 'associated_index'
    end

    rename_column :audits, :associated_type, :association_type
    rename_column :audits, :associated_id, :association_id

    add_index :audits, [:association_id, :association_type], :name => 'association_index'
  end
end

Version data entries

42 entries across 38 versions & 7 rubygems

Version Path
acts_as_audited-2.1.0 lib/generators/acts_as_audited/templates/rename_association_to_associated.rb
acts_as_audited-2.0.0 lib/generators/acts_as_audited/templates/rename_association_to_associated.rb