Prev | Current Page 120 | Next

David Berube

"Practical Reporting with Ruby and Rails"

Fortunately, Rails creates the
skeleton containing the class definition and method names, so you only need to fill out
the migration. Let??™s do that now. Listing 5-2 shows the full migration class.
Listing 5-2. Application Schema (db/migrate/001_initial_schema.rb)
class InitialSchema < ActiveRecord::Migration
def self.up
create_table :actors do |t|
t.column :name, :string, :length=>45
t.column :phone, :string, :length=>13
end
create_table :projects do |t|
t.column :name, :string, :length=>25
end
create_table :rooms do |t|
t.column :name, :string, :length=>25
end
create_table :bookings do |t|
t.column :actor_id, :integer
t.column :room_id, :integer
t.column :project_id, :integer
t.column :booked_at, :datetime
end
end
CHAPTER 5 n CONNECTING YOUR REPORTS TO THE WORLD 79
def self.down
drop_table :actors
drop_table :projects
drop_table :rooms
drop_table :bookings
end
end
Save this as db/migrate/001_initial_schema.rb.
Next, run the migration to create the database structure that the migration describes,
using the following command:
rake db:migrate
(in /your_path/your_directory/actor_schedule)
== InitialSchema: migrating ===================================================
-- create_table(:actors)
-> 0.


Pages:
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
Władysławowo noclegi katalog stron budowlanych pozycjonowanie stron w google międzyzdroje noclegi Opoczno