Prev | Current Page 131 | Next

David Berube

"Practical Reporting with Ruby and Rails"

up
create_table :actors do |t|
t.column :name, :text, :length=>45
t.column :phone, :text, :length=>13
end
create_table :projects do |t|
t.column :name, :text, :length=>25
end
create_table :rooms do |t|
t.column :name, :text, :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 89
def self.down
drop_table :actors
drop_table :projects
drop_table :rooms
drop_table :bookings
end
end
This migration has two methods: up and down. The up method creates several tables
using the Rails built-in column types, which are automatically mapped to databasespecific
types. The down method drops the tables and is used to undo a migration. Notice
that these tables automatically have an artificial primary key column, id, added by
default. If that is undesirable, you need to explicitly state you don??™t want an id column,
by using the ;id=>false option in your create_table statement.


Pages:
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
Spa Ciechocinek drzwiowe hosting hotele londyn xiden.bosten.pl