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
notifiably_audited-activerecord-2.1.0 lib/generators/audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-2.0.0 lib/generators/audited/templates/rename_association_to_associated.rb
audited-hp-4.3.1 lib/generators/audited/templates/rename_association_to_associated.rb
audited-hp-4.3.0 lib/generators/audited/templates/rename_association_to_associated.rb
audited-4.3.0 lib/generators/audited/templates/rename_association_to_associated.rb
audited-activerecord-4.2.2 lib/generators/audited/templates/rename_association_to_associated.rb
audited-activerecord-4.2.1 lib/generators/audited/templates/rename_association_to_associated.rb
audited-activerecord-4.2.0 lib/generators/audited/templates/rename_association_to_associated.rb
audited-activerecord-4.0.0 lib/generators/audited/templates/rename_association_to_associated.rb
audited-activerecord-4.0.0.rc1 lib/generators/audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.10 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.9 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.8 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.7 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.6 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.5 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.4 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.3 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.2 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb
notifiably_audited-activerecord-1.0.1 lib/generators/notifiably_audited/templates/rename_association_to_associated.rb