02 Oct '13, 1am

migration の change の一部だけ up と down の処理を分けたいときは reversible というのを使うのか。

class SerializeProductListMigration < ActiveRecord::Migration def change add_column :categories, :product_list reversible do |dir| dir.up do # transfer data from Products to Category#product_list end dir.down do # create Products from Category#product_list end end revert do # copy-pasted code from ExampleMigration create_table :products do |t| t.references :category end reversible do |dir| dir.up do #add a foreign key execute <<-SQL ALTER TABLE products ADD CONSTRAINT fk_products_categories FOREIGN KEY (category_id) REFERENCES categories(id) SQL end dir.down do execute <<-SQL ALTER TABLE products DROP FOREIGN KEY fk_products_categories SQL end end # The rest of the migration was ok end end end

Full article: http://guides.rubyonrails.org/migrations.html#using-rever...

Tweets

ほんとだ、ちゃんと reset_column_information について書いてあった >...

guides.rubyonrails.org 26 Sep '13, 9am

You can think of each migration as being a new 'version' of the database. A schema starts off with nothing in it, and each...

7 things to know about the new UN climate change report

7 things to know about the new UN climate chang...

greenbiz.com 01 Oct '13, 10am

On Friday, the United Nations' Intergovernmental Panel on Climate Change (IPCC) released its latest report -- the fifth si...

“Active Record Validations — Ruby on Rails Guides”

edgeguides.rubyonrails.org 11 Oct '13, 8am

Database constraints and/or stored procedures make the validation mechanisms database-dependent and can make testing and m...

#Ruby on #Rails: Deploy

rubyonrails.org 05 Oct '13, 12am

The easiest deployment setup for Rails is Phusion Passenger aka mod_rails. It's a module for nginx and Apache that automat...

“Active Record Basics — Ruby on Rails Guides”

guides.rubyonrails.org 12 Oct '13, 1pm

When writing applications using other programming languages or frameworks, it may be necessary to write a lot of configura...