class BuildDb < ActiveRecord::Migration
  def self.up

    create_table :books do |t|
      t.column :name, :string
    end

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

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