Prev | Current Page 138 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

When you run script/generate
migration from your Rails root and give it a name, it will generate a file using the next number
available. For example, executing the command script/generate migration create_users_
table will make a file in db/migrate called 001_create_users_table.rb.
Running the migrations to apply the Active Record schema to your database schema
within the Rails framework is done with a Ruby on Rails rake task and can move the migration
version up or down to any specific revision using a command like rake db:migrate [VERSION=X].
CHAPTER 3 ?–  SETTING UP YOUR DATABASE 48
?– Note If you leave off the VERSION parameter, it will attempt to migrate the database as high as it can go
by adding one to the highest version number found in the schema_info table.
Executing Migrations Outside of Ruby on Rails
The rake method for generating and running migrations described previously is only valid if
you are working from within the Ruby on Rails framework. As we mentioned, though, you can
still use migrations outside of the Rails framework, you will just need to create your own script
to run the migrations.


Pages:
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150