class BuildDb < ActiveRecord::Migration
  def self.up

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

    mysql_book = Book.create :name => 'MySQL. Receptury'

    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 => 'Obsługa programu mysql',
                   :position => 1
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Pisanie programów opartych o MySQL',
                   :position => 2
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Techniki selekcji rekordów',
                   :position => 3
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Praca z łańcuchami',
                   :position => 4
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Obsługa daty i czasu',
                   :position => 5
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Sortowanie wyników zapytań',
                   :position => 6
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Tworzenie podsumowań',
                   :position => 7
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Modyfikowanie tabel przy użyciu ALTER TABLE',
                   :position => 8
    Chapter.create :book_id => mysql_book.id, 
                   :name => 'Pozyskiwanie i obsługa metadanych',
                   :position => 9
    Chapter.create :book_id => mysql_book.id, 
                    :name => 'Import i eksport danych',
                    :position => 10
  end

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