diff options
Diffstat (limited to 'railties/guides/source/migrations.textile')
-rw-r--r-- | railties/guides/source/migrations.textile | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile index 0d13fbc10a..21784c5ba3 100644 --- a/railties/guides/source/migrations.textile +++ b/railties/guides/source/migrations.textile @@ -109,7 +109,7 @@ h4. Creating a Model The model and scaffold generators will create migrations appropriate for adding a new model. This migration will already contain instructions for creating the relevant table. If you tell Rails what columns you want then statements for adding those will also be created. For example, running <shell> -rails generate model Product name:string description:text +$ rails generate model Product name:string description:text </shell> will create a migration that looks like this @@ -139,7 +139,7 @@ h4. Creating a Standalone Migration If you are creating migrations for other purposes (for example to add a column to an existing table) then you can use the migration generator: <shell> -rails generate migration AddPartNumberToProducts +$ rails generate migration AddPartNumberToProducts </shell> This will create an empty but appropriately named migration: @@ -157,7 +157,7 @@ end If the migration name is of the form "AddXXXToYYY" or "RemoveXXXFromYYY" and is followed by a list of column names and types then a migration containing the appropriate +add_column+ and +remove_column+ statements will be created. <shell> -rails generate migration AddPartNumberToProducts part_number:string +$ rails generate migration AddPartNumberToProducts part_number:string </shell> will generate @@ -177,7 +177,7 @@ end Similarly, <shell> -rails generate migration RemovePartNumberFromProducts part_number:string +$ rails generate migration RemovePartNumberFromProducts part_number:string </shell> generates @@ -197,7 +197,7 @@ end You are not limited to one magically generated column, for example <shell> -rails generate migration AddDetailsToProducts part_number:string price:decimal +$ rails generate migration AddDetailsToProducts part_number:string price:decimal </shell> generates @@ -383,7 +383,7 @@ If you specify a target version, Active Record will run the required migrations version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run <shell> -rake db:migrate VERSION=20080906120000 +$ rake db:migrate VERSION=20080906120000 </shell> If this is greater than the current version (i.e. it is migrating upwards) this will run the +up+ method on all migrations up to and including 20080906120000, if migrating downwards this will run the +down+ method on all the migrations down to, but not including, 20080906120000. @@ -393,13 +393,13 @@ h4. Rolling Back A common task is to rollback the last migration, for example if you made a mistake in it and wish to correct it. Rather than tracking down the version number associated with the previous migration you can run <shell> -rake db:rollback +$ rake db:rollback </shell> This will run the +down+ method from the latest migration. If you need to undo several migrations you can provide a +STEP+ parameter: <shell> -rake db:rollback STEP=3 +$ rake db:rollback STEP=3 </shell> will run the +down+ method from the last 3 migrations. @@ -407,7 +407,7 @@ will run the +down+ method from the last 3 migrations. The +db:migrate:redo+ task is a shortcut for doing a rollback and then migrating back up again. As with the +db:rollback+ task you can use the +STEP+ parameter if you need to go more than one version back, for example <shell> -rake db:migrate:redo STEP=3 +$ rake db:migrate:redo STEP=3 </shell> Neither of these Rake tasks do anything you could not do with +db:migrate+, they are simply more convenient since you do not need to explicitly specify the version to migrate to. @@ -421,7 +421,7 @@ h4. Being Specific If you need to run a specific migration up or down the +db:migrate:up+ and +db:migrate:down+ tasks will do that. Just specify the appropriate version and the corresponding migration will have its +up+ or +down+ method invoked, for example <shell> -rake db:migrate:up VERSION=20080906120000 +$ rake db:migrate:up VERSION=20080906120000 </shell> will run the +up+ method from the 20080906120000 migration. These tasks check whether the migration has already run, so for example +db:migrate:up VERSION=20080906120000+ will do nothing if Active Record believes that 20080906120000 has already been run. |