SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 143 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"


With all of this in mind, we are finally ready to start coding our migrations! Throughout
the rest of this chapter, we??™ll walk you through the various CRUD operations as they relate to
migrations, and where possible, we??™ll compare and contrast the migration approach to that of
the traditional database development approach.
Creating Tables
The first thing you??™re going to want to do when you start using migrations is create the tables
that you??™re going to be using for your application.
Since this is our first migration and we want to move forward with our development
process, we??™ll be using the up method. And since we want to create our first table, we??™ll be
using the create_table method to give the table its definition. In the following code we create
a cows table:
# Script to create the first version of a cows table
def self.up
create_table :cows do |t|
t.column :name, :string
t.column :breed, :string
t.column :born_on, :datetime
t.column :milkable, :boolean
end
end
Before the code is run, your application database should be empty.


Pages:
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6