Sha256: 0afe2922a1dd11b30072b3b07641c321ca877552b2bc4a94bfc3e4cc8b722e61
Contents?: true
Size: 900 Bytes
Versions: 6
Compression:
Stored size: 900 Bytes
Contents
class AddBlogIds < ActiveRecord::Migration class Blog < ActiveRecord::Base; end class Content < ActiveRecord::Base; end class Sidebar < ActiveRecord::Base; end def up add_column :contents, :blog_id, :integer add_column :sidebars, :blog_id, :integer if Content.any? || Sidebar.any? default_blog_id = Blog.order(:id).first.id Content.update_all("blog_id = #{default_blog_id}") Sidebar.update_all("blog_id = #{default_blog_id}") end change_column :sidebars, :blog_id, :integer, :null => false end def down if adapter_name == 'PostgreSQL' indexes(:contents).each do |index| if index.name =~ /blog_id/ remove_index(:contents, :name => index.name) end end else remove_index :contents, :blog_id rescue nil end remove_column :contents, :blog_id remove_column :sidebars, :blog_id end end
Version data entries
6 entries across 6 versions & 1 rubygems