class BuildDb < ActiveRecord::Migration
  def self.up
    create_table :books do |t|
      t.column :name, :string
    end

    book = Book.create :name => 'MySQL Cookbook'

    create_table :chapters do |t|
      t.column :book_id, :integer
      t.column :name, :string
      t.column :position, :integer
    end

    Chapter.create :book_id => book.id,
                   :name => 'Using the mysql Client Program', :position => 1 
    Chapter.create :book_id => book.id, 
                   :name => 'Writing MySQL-Based Programs', :position => 2 
    Chapter.create :book_id => book.id, 
                   :name => 'Record Selection Techniques', :position => 3 
    Chapter.create :book_id => book.id, 
                   :name => 'Working with Strings', :position => 4 
    Chapter.create :book_id => book.id, 
                   :name => 'Working with Dates and Times', :position => 5 
    Chapter.create :book_id => book.id, 
                   :name => 'Sorting Query Results', :position => 6 
    Chapter.create :book_id => book.id, 
                   :name => 'Generating Summaries', :position => 7
    Chapter.create :book_id => book.id, 
                   :name => 'Modifying Tables with ALTER TABLE', :position => 8
    Chapter.create :book_id => book.id, 
                   :name => 'Obtaining and Using Metadata', :position => 9
    Chapter.create :book_id => book.id, 
                   :name => 'Importing and Exporting Data', :position => 10
  end

  def self.down
    drop_table :books
    drop_table :chapters
  end
end