Sha256: 36261102d7028930651318e5c7125eb559671c6a27d31dad87d5d73d885163fb

Contents?: true

Size: 738 Bytes

Versions: 30

Compression:

Stored size: 738 Bytes

Contents

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

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
typo-5.5 db/migrate/040_attach_content_to_blog.rb
typo-5.4.4 db/migrate/040_attach_content_to_blog.rb
typo-5.4.3 db/migrate/040_attach_content_to_blog.rb
typo-5.4.2 db/migrate/040_attach_content_to_blog.rb
typo-5.4.1 db/migrate/040_attach_content_to_blog.rb
typo-5.4 db/migrate/040_attach_content_to_blog.rb
typo-3.99.0 db/migrate/040_attach_content_to_blog.rb
typo-3.99.3 db/migrate/040_attach_content_to_blog.rb
typo-3.99.1 db/migrate/040_attach_content_to_blog.rb
typo-3.99.2 db/migrate/040_attach_content_to_blog.rb
typo-4.0.0 db/migrate/040_attach_content_to_blog.rb
typo-4.0.2 db/migrate/040_attach_content_to_blog.rb
typo-3.99.4 db/migrate/040_attach_content_to_blog.rb
typo-4.0.1 db/migrate/040_attach_content_to_blog.rb
typo-4.1.1 db/migrate/040_attach_content_to_blog.rb
typo-4.0.3 db/migrate/040_attach_content_to_blog.rb
typo-4.1 db/migrate/040_attach_content_to_blog.rb
typo-5.0.1 db/migrate/040_attach_content_to_blog.rb
typo-5.0.2 db/migrate/040_attach_content_to_blog.rb
typo-5.0.3.98.1 db/migrate/040_attach_content_to_blog.rb