Project

General

Profile

Feature #236 » 0002-Refactored-latest-migrations-to-actually-migrate-dat.patch

New migrations - Jochen Schalanda, 05/23/2010 03:52 PM

View differences:

db/migrate/20100522142706_remove_operatingsystem_id_from_medias.rb
class RemoveOperatingsystemIdFromMedias < ActiveRecord::Migration
def self.up
remove_column :medias, :operatingsystem_id
end
def self.down
add_column :medias, :operatingsystem_id, :integer
end
end
db/migrate/20100522143100_create_medias_operatingsystems.rb
class CreateMediasOperatingsystems < ActiveRecord::Migration
def self.up
create_table :medias_operatingsystems , :id => false do |t|
t.references :media, :null => false
t.references :operatingsystem, :null => false
end
end
def self.down
drop_table :medias_operatingsystems
end
end
db/migrate/20100523141204_create_medias_operatingsystems_and_migrate_data.rb
class CreateMediasOperatingsystemsAndMigrateData < ActiveRecord::Migration
def self.up
create_table :medias_operatingsystems , :id => false do |t|
t.references :media, :null => false
t.references :operatingsystem, :null => false
end
media_hash = Hash.new
Media.all.each { |medium|
unless medium.operatingsystem_id.nil?
os = Operatingsystem.find(medium.operatingsystem_id)
media_hash[os] = medium
end
}
media_hash.keys.each { |os|
os.medias << media_hash[os]
}
remove_column :medias, :operatingsystem_id
end
def self.down
add_column :medias, :operatingsystem_id, :integer
drop_table :medias_operatingsystems
end
end
(2-2/2)