Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

29 lines (25 sloc) 0.738 kb
class AttachContentToBlog < ActiveRecord::Migration
class BareContent < ActiveRecord::Base
include BareMigration
end
class BareBlog < ActiveRecord::Base
include BareMigration
end
def self.up
begin
add_column :contents, :blog_id, :integer
blog_id = BareBlog.find(:first).id
BareContent.find(:all).each {|c| c.blog_id = blog_id; c.save! }
change_column :contents, :blog_id, :integer, :null => false
add_index :contents, :blog_id
rescue Exception => e
remove_index :contents, :blog_id rescue nil
remove_column :contents, :blog_id rescue nil
raise e
end
end
def self.down
remove_index :contents, :blog_id
remove_column :contents, :blog_id
end
end
Jump to Line
Something went wrong with that request. Please try again.