040_attach_content_to_blog.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:
Ajax
开发平台:
Others
- 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