Sha256: ef9f824d6a31da17d20886427b6af614cd0989af93f359d8560747fd0bb6f596

Contents?: true

Size: 675 Bytes

Versions: 3

Compression:

Stored size: 675 Bytes

Contents

def create_blog_tables 
  connection = ActiveRecord::Base.connection
  
  [:post_tags, :comments, :posts, :tags].each do |table|
    connection.drop_table table  if connection.table_exists? table
  end

  connection.create_table :posts do |t|
    t.string :title
    t.text   :body
  end
  connection.create_table :comments do |t|
    t.integer     :post_id
    t.foreign_key :posts,    :dependent => :delete
    t.text        :body
  end
  connection.create_table :tags do |t|
    t.string     :name
  end
  connection.create_table :post_tags, :id=>false do |t|
    t.integer     :post_id
    t.foreign_key :posts
    t.integer     :tag_id
    t.foreign_key :tags
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
legacy_data-0.1.11 examples/blog_migration.rb
legacy_data-0.1.10 examples/blog_migration.rb
legacy_data-0.1.9 examples/blog_migration.rb