Sha256: 76a7286842272728234f399b0f41971c5d1ee24ffe6b1af0c5ca73f476d01211
Contents?: true
Size: 911 Bytes
Versions: 5
Compression:
Stored size: 911 Bytes
Contents
class CreateMediaOperatingsystemsAndMigrateData < ActiveRecord::Migration class Medium < ActiveRecord::Base; end def self.up medium_hash = Hash.new Medium.all.each do |medium| unless medium.operatingsystem_id.nil? if Operatingsystem.exists?(medium.operatingsystem_id) os = Operatingsystem.find(medium.operatingsystem_id) medium_hash[os] = medium else say "skipped #{medium}" end end end create_table :media_operatingsystems , :id => false do |t| t.references :medium, :null => false t.references :operatingsystem, :null => false end medium_hash.keys.each { |os| os.media << medium_hash[os] } remove_column :media, :operatingsystem_id Medium.reset_column_information end def self.down add_column :media, :operatingsystem_id, :integer drop_table :media_operatingsystems end end
Version data entries
5 entries across 5 versions & 1 rubygems