Updated

db/migrate / 20170821153057_migrate_sponsors_to_signature_attribute.rb

B
36 lines of codes
2 methods
10.3 complexity/method
1 churn
20.56 complexity
23 duplications
class MigrateSponsorsToSignatureAttribute < ActiveRecord::Migration
  1. MigrateSponsorsToSignatureAttribute has no descriptive comment
class Sponsor < ActiveRecord::Base; end
  1. MigrateSponsorsToSignatureAttribute::Sponsor has no descriptive comment
class Signature < ActiveRecord::Base; end
  1. MigrateSponsorsToSignatureAttribute::Signature has no descriptive comment
def up
  1. MigrateSponsorsToSignatureAttribute#up has approx 6 statements
add_column :signatures, :sponsor, :boolean, null: false, default: false # Migrate any data (should be dev environment only) sponsors = Sponsor.pluck(:signature_id) Signature.where(id: sponsors).update_all(sponsor: true) remove_foreign_key :sponsors, :petitions remove_foreign_key :sponsors, :signatures drop_table :sponsors end def down
  1. MigrateSponsorsToSignatureAttribute#down has approx 11 statements
create_table :sponsors do |t|
  1. Similar code found in 3 nodes Locations: 0 1 2
  2. MigrateSponsorsToSignatureAttribute#down has the variable name 't'
t.integer :petition_id t.integer :signature_id t.datetime :created_at, null: false t.datetime :updated_at, null: false end add_foreign_key :sponsors, :petitions, on_delete: :cascade add_foreign_key :sponsors, :signatures, on_delete: :cascade # Migrate any data (should be dev environment only) signatures = Signature.where(sponsor: true).pluck(:id, :petition_id) signatures.each do |signature_id, petition_id| Sponsor.create!(signature_id: signature_id, petition_id: petition_id) end remove_column :signatures, :sponsor end end