Updated

db/migrate / 20170611131130_add_parliament_id_to_archived_petitions.rb

A
30 lines of codes
2 methods
8.6 complexity/method
3 churn
17.14 complexity
0 duplications
class AddParliamentIdToArchivedPetitions < ActiveRecord::Migration
  1. AddParliamentIdToArchivedPetitions has no descriptive comment
class Parliament < ActiveRecord::Base; end
  1. AddParliamentIdToArchivedPetitions::Parliament has no descriptive comment
class ArchivedPetition < ActiveRecord::Base; end
  1. AddParliamentIdToArchivedPetitions::ArchivedPetition has no descriptive comment
def up
  1. AddParliamentIdToArchivedPetitions#up has approx 7 statements
add_column :archived_petitions, :parliament_id, :integer add_index :archived_petitions, :parliament_id add_foreign_key :archived_petitions, :parliaments Parliament.reset_column_information ArchivedPetition.reset_column_information parliament = Parliament.create!( government: "Conservative – Liberal Democrat coalition", opening_at: "2010-05-18T00:00:00".in_time_zone, dissolution_at: "2015-03-30T23:59:59".in_time_zone, archived_at: "2015-07-20T00:00:00".in_time_zone ) ArchivedPetition.update_all(parliament_id: parliament.id) end def down remove_foreign_key :archived_petitions, :parliaments remove_column :archived_petitions, :parliament_id parliament = Parliament.find_by!(opening_at: "2010-05-18T00:00:00".in_time_zone) parliament.destroy end end