Updated

db/migrate / 20170906203439_migrate_creator_to_signature_attribute.rb

A
34 lines of codes
2 methods
10.5 complexity/method
1 churn
20.94 complexity
0 duplications
class MigrateCreatorToSignatureAttribute < ActiveRecord::Migration
  1. MigrateCreatorToSignatureAttribute has no descriptive comment
class Petition < ActiveRecord::Base; end
  1. MigrateCreatorToSignatureAttribute::Petition has no descriptive comment
class Signature < ActiveRecord::Base; end
  1. MigrateCreatorToSignatureAttribute::Signature has no descriptive comment
def up
  1. MigrateCreatorToSignatureAttribute#up has approx 7 statements
add_column :signatures, :creator, :boolean, null: false, default: false # Migrate any data (should be dev environment only) signatures = Petition.pluck(:creator_signature_id) Signature.where(id: signatures).update_all(creator: true) add_index :signatures, :petition_id, where: "creator = 't'", unique: true, name: "index_signatures_on_petition_id_where_creator_is_true" remove_foreign_key :petitions, column: :creator_signature_id remove_index :petitions, :creator_signature_id remove_column :petitions, :creator_signature_id end def down
  1. MigrateCreatorToSignatureAttribute#down has approx 10 statements
add_column :petitions, :creator_signature_id, :integer add_index :petitions, :creator_signature_id, unique: true add_foreign_key :petitions, :signatures, column: :creator_signature_id, on_delete: :restrict # Migrate any data (should be dev environment only) signatures = Signature.where(creator: true).pluck(:id, :petition_id) signatures.each do |signature_id, petition_id| Petition.where(id: petition_id).update_all(creator_signature_id: signature_id) end change_column_null :petitions, :creator_signature_id, false change_column_default :petitions, :creator_signature_id, nil remove_index :signatures, name: "index_archived_signatures_on_petition_id_where_creator_is_true" remove_column :signatures, :creator end end