From 5adb90a14f3fc3441a53476dd75217d1ecb8de97 Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Wed, 3 Aug 2011 19:11:22 +0530
Subject: fixed incorrect tags

---
 railties/guides/source/migrations.textile | 32 +++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index e51ee0f535..7b501807d6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -477,7 +477,7 @@ Several methods are provided that allow you to control all this:
 
 For example, this migration
 
-<pre>
+<ruby>
 class CreateProducts < ActiveRecord::Migration
   def change
     suppress_messages do
@@ -496,7 +496,7 @@ class CreateProducts < ActiveRecord::Migration
     end
   end
 end
-</pre>
+</ruby>
 
 generates the following output
 
@@ -525,7 +525,7 @@ Bob goes on vacation.
 Alice creates a migration for the +products+ table which adds a new column and initializes it.
 She also adds a validation to the Product model for the new column.
 
-<pre>
+<ruby>
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -534,19 +534,19 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => 'false') }
   end
 end
-</pre>
+</ruby>
 
-<pre>
+<ruby>
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
 end
-</pre>
+</ruby>
 
 Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column.
 
-<pre>
+<ruby>
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -555,16 +555,16 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-</pre>
+</ruby>
 
-<pre>
+<ruby>
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
   validates_presence_of :flag
   validates_presence_of :fuzz
 end
-</pre>
+</ruby>
 
 Both migrations work for Alice.
 
@@ -575,12 +575,12 @@ Bob comes back from vacation and:
 
 The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs.
 
-<pre>
+<plain>
 rake aborted!
 An error has occurred, this and all later migrations canceled:
 
 undefined method `fuzz' for #<Product:0x000001049b14a0>
-</pre>
+</plain>
 
 A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion.
 
@@ -588,7 +588,7 @@ When using a faux model, it's a good idea to call +Product.reset_column_informat
 
 If Alice had done this instead, there would have been no problem:
 
-<pre>
+<ruby>
 # db/migrate/20100513121110_add_flag_to_product.rb
 
 class AddFlagToProduct < ActiveRecord::Migration
@@ -600,9 +600,9 @@ class AddFlagToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes!(:flag => false) }
   end
 end
-</pre>
+</ruby>
 
-<pre>
+<ruby>
 # db/migrate/20100515121110_add_fuzz_to_product.rb
 
 class AddFuzzToProduct < ActiveRecord::Migration
@@ -614,7 +614,7 @@ class AddFuzzToProduct < ActiveRecord::Migration
     Product.all.each { |f| f.update_attributes! :fuzz => 'fuzzy' }
   end
 end
-</pre>
+</ruby>
 
 
 h3. Schema Dumping and You
-- 
cgit v1.2.3


From 688b0c318f411a65bb2e27614dd9fe004427a344 Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Wed, 3 Aug 2011 19:13:12 +0530
Subject: minor changes in migrations guide

---
 railties/guides/source/migrations.textile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 7b501807d6..4476e067a6 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -540,7 +540,7 @@ end
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
-  validates_presence_of :flag
+  validates :flag, :presence => true
 end
 </ruby>
 
@@ -561,8 +561,7 @@ end
 # app/model/product.rb
 
 class Product < ActiveRecord::Base
-  validates_presence_of :flag
-  validates_presence_of :fuzz
+  validates :flag, :fuzz, :presence => true
 end
 </ruby>
 
@@ -594,9 +593,10 @@ If Alice had done this instead, there would have been no problem:
 class AddFlagToProduct < ActiveRecord::Migration
   class Product < ActiveRecord::Base
   end
+
   def change
     add_column :products, :flag, :int
-    Product.reset_column_information  
+    Product.reset_column_information
     Product.all.each { |f| f.update_attributes!(:flag => false) }
   end
 end
-- 
cgit v1.2.3


From ac4dc5e240242ed53885e4cac7b48dd93773a329 Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Sun, 14 Aug 2011 20:15:51 +0530
Subject: rephrase how the verbose methods in a migration work

---
 railties/guides/source/migrations.textile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 4476e067a6..9da12e2e18 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -471,8 +471,8 @@ By default migrations tell you exactly what they're doing and how long it took.
 
 Several methods are provided that allow you to control all this:
 
-* +suppress_messages+ suppresses any output generated by its block
-* +say+ outputs text (the second argument controls whether it is indented or not)
+* +suppress_messages+ takes a block as an argument and suppresses any output generated by the block.
+* +say+ takes a message argument and outputs it as is. A second boolean argument can be passed to specify whether to indent or not.
 * +say_with_time+ outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected.
 
 For example, this migration
@@ -510,7 +510,7 @@ generates the following output
 20080906170109 CreateProducts: migrated (10.0097s)
 </shell>
 
-If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress any output.
+If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress all output.
 
 h3. Using Models in Your Migrations
 
-- 
cgit v1.2.3


From f302370c0527cd5f24889e7068134e59b65b40f1 Mon Sep 17 00:00:00 2001
From: Jeff Dutil <jdutil21@gmail.com>
Date: Tue, 16 Aug 2011 22:59:36 -0400
Subject: Fix ruby typo to correctly render code block in initializer.textile

---
 railties/guides/source/migrations.textile | 1 +
 1 file changed, 1 insertion(+)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 9da12e2e18..6fcc3cf4a2 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -300,6 +300,7 @@ change_table :products do |t|
   t.rename :upccode, :upc_code
 end
 </ruby>
+
 removes the +description+ and +name+ columns, creates a +part_number+ column and adds an index on it. Finally it renames the +upccode+ column. This is the same as doing
 
 <ruby>
-- 
cgit v1.2.3


From 9980f46ca2d250d1d3e2fac84c5dc9ca6cbab1ea Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Thu, 15 Sep 2011 00:13:29 +0530
Subject: No more changelogs inside guides

---
 railties/guides/source/migrations.textile | 6 ------
 1 file changed, 6 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 6fcc3cf4a2..7faa18e888 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -673,9 +673,3 @@ The Active Record way claims that intelligence belongs in your models, not in th
 Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
 
 Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
-
-h3. Changelog
-
-* April 26, 2011: change generated +up+ and +down+ methods to +change+ method, and describe detail about +change+ method by "Prem Sichanugrist":http://sikachu.com
-* July 15, 2010: minor typos corrected by "Jaime Iniesta":http://jaimeiniesta.com
-* September 14, 2008: initial version by "Frederick Cheung":credits.html#fcheung
-- 
cgit v1.2.3


From e3d4603151db945ebab950c1f5095e29e6369b11 Mon Sep 17 00:00:00 2001
From: Manuel Menezes de Sequeira <MMSequeira@gmail.com>
Date: Mon, 3 Oct 2011 14:47:24 +0100
Subject: Several small corrections and improvements to the Migrations and
 Active Record Basics guides.

---
 railties/guides/source/migrations.textile | 62 +++++++++++++++----------------
 1 file changed, 30 insertions(+), 32 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 7faa18e888..a73655d130 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -91,13 +91,13 @@ Active Record provides methods that perform common data definition tasks in a da
 * +add_index+
 * +remove_index+
 
-If you need to perform tasks specific to your database (for example create a "foreign key":#active-record-and-referential-integrity constraint) then the +execute+ function allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).
+If you need to perform tasks specific to your database (for example create a "foreign key":#active-record-and-referential-integrity constraint) then the +execute+ method allows you to execute arbitrary SQL. A migration is just a regular Ruby class so you're not limited to these functions. For example after adding a column you could write code to set the value of that column for existing records (if necessary using your models).
 
 On databases that support transactions with statements that change the schema (such as PostgreSQL or SQLite3), migrations are wrapped in a transaction. If the database does not support this (for example MySQL) then when a migration fails the parts of it that succeeded will not be rolled back. You will have to unpick the changes that were made by hand.
 
 h4. What's in a Name
 
-Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you <em>have to</em> update the name of the class inside or Rails will complain about a missing class.
+Migrations are stored in files in +db/migrate+, one for each migration class. The name of the file is of the form +YYYYMMDDHHMMSS_create_products.rb+, that is to say a UTC timestamp identifying the migration followed by an underscore followed by the name of the migration. The name of the migration class (CamelCased version) should match the latter part of the file name. For example +20080906120000_create_products.rb+ should define class +CreateProducts+ and +20080906120001_add_details_to_products.rb+ should define +AddDetailsToProducts+. If you do feel the need to change the file name then you <em>have to</em> update the name of the class inside or Rails will complain about a missing class.
 
 Internally Rails only uses the migration's number (the timestamp) to identify them. Prior to Rails 2.1 the migration number started at 1 and was incremented each time a migration was generated. With multiple developers it was easy for these to clash requiring you to rollback migrations and renumber them. With Rails 2.1 this is largely avoided by using the creation time of the migration to identify them. You can revert to the old numbering scheme by adding the following line to +config/application.rb+.
 
@@ -115,7 +115,7 @@ h4. Changing Migrations
 
 Occasionally you will make a mistake when writing a migration. If you have already run the migration then you cannot just edit the migration and run the migration again: Rails thinks it has already run the migration and so will do nothing when you run +rake db:migrate+. You must rollback the migration (for example with +rake db:rollback+), edit your migration and then run +rake db:migrate+ to run the corrected version.
 
-In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or more generally which has not been propagated beyond your development machine) is relatively harmless.
+In general editing existing migrations is not a good idea: you will be creating extra work for yourself and your co-workers and cause major headaches if the existing version of the migration has already been run on production machines. Instead, you should write a new migration that performs the changes you require. Editing a freshly generated migration that has not yet been committed to source control (or, more generally, which has not been propagated beyond your development machine) is relatively harmless.
 
 h4. Supported Types
 
@@ -134,7 +134,7 @@ Active Record supports the following types:
 * +:binary+
 * +:boolean+
 
-These will be mapped onto an appropriate underlying database type, for example with MySQL +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example
+These will be mapped onto an appropriate underlying database type. For example, with MySQL the type +:string+ is mapped to +VARCHAR(255)+. You can create columns of types not supported by Active Record when using the non-sexy syntax, for example
 
 <ruby>
 create_table :products do |t|
@@ -148,7 +148,7 @@ h3. Creating a Migration
 
 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
+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 these columns will also be created. For example, running
 
 <shell>
 $ rails generate model Product name:string description:text
@@ -262,7 +262,7 @@ end
 
 which creates a +products+ table with a column called +name+ (and as discussed below, an implicit +id+ column).
 
-The object yielded to the block allows you to create columns on the table. There are two ways of doing this: The first (traditional) form looks like
+The object yielded to the block allows you to create columns on the table. There are two ways of doing it. The first (traditional) form looks like
 
 <ruby>
 create_table :products do |t|
@@ -270,7 +270,7 @@ create_table :products do |t|
 end
 </ruby>
 
-the second form, the so called "sexy" migration, drops the somewhat redundant +column+ method. Instead, the +string+, +integer+, etc. methods create a column of that type. Subsequent parameters are the same.
+The second form, the so called "sexy" migration, drops the somewhat redundant +column+ method. Instead, the +string+, +integer+, etc. methods create a column of that type. Subsequent parameters are the same.
 
 <ruby>
 create_table :products do |t|
@@ -278,7 +278,7 @@ create_table :products do |t|
 end
 </ruby>
 
-By default +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or if you don't want a primary key at all (for example for a HABTM join table) you can pass +:id => false+. If you need to pass database specific options you can place an SQL fragment in the +:options+ option. For example
+By default, +create_table+ will create a primary key called +id+. You can change the name of the primary key with the +:primary_key+ option (don't forget to update the corresponding model) or, if you don't want a primary key at all (for example for a HABTM join table), you can pass the option +:id => false+. If you need to pass database specific options you can place an SQL fragment in the +:options+ option. For example,
 
 <ruby>
 create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
@@ -286,7 +286,7 @@ create_table :products, :options => "ENGINE=BLACKHOLE" do |t|
 end
 </ruby>
 
-will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL the default is +ENGINE=InnoDB+).
+will append +ENGINE=BLACKHOLE+ to the SQL statement used to create the table (when using MySQL, the default is +ENGINE=InnoDB+).
 
 h4. Changing Tables
 
@@ -348,11 +348,11 @@ end
 </ruby>
 will add an +attachment_id+ column and a string +attachment_type+ column with a default value of 'Photo'.
 
-NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ for that or a plugin that adds "foreign key support":#active-record-and-referential-integrity.
+NOTE: The +references+ helper does not actually create foreign key constraints for you. You will need to use +execute+ or a plugin that adds "foreign key support":#active-record-and-referential-integrity.
 
-If the helpers provided by Active Record aren't enough you can use the +execute+ function to execute arbitrary SQL.
+If the helpers provided by Active Record aren't enough you can use the +execute+ method to execute arbitrary SQL.
 
-For more details and examples of individual methods check the API documentation, in particular the documentation for "<tt>ActiveRecord::ConnectionAdapters::SchemaStatements</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html (which provides the methods available in the +up+ and +down+ methods), "<tt>ActiveRecord::ConnectionAdapters::TableDefinition</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html (which provides the methods available on the object yielded by +create_table+) and "<tt>ActiveRecord::ConnectionAdapters::Table</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html (which provides the methods available on the object yielded by +change_table+).
+For more details and examples of individual methods, check the API documentation, in particular the documentation for "<tt>ActiveRecord::ConnectionAdapters::SchemaStatements</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html (which provides the methods available in the +up+ and +down+ methods), "<tt>ActiveRecord::ConnectionAdapters::TableDefinition</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html (which provides the methods available on the object yielded by +create_table+) and "<tt>ActiveRecord::ConnectionAdapters::Table</tt>":http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html (which provides the methods available on the object yielded by +change_table+).
 
 h4. Writing Your +change+ Method
 
@@ -371,7 +371,7 @@ If you're going to use other methods, you'll have to write the +up+ and +down+ m
 
 h4. Writing Your +down+ Method
 
-The +down+ method of your migration should revert the transformations done by the +up+ method. In other words the database schema should be unchanged if you do an +up+ followed by a +down+. For example if you create a table in the +up+ method you should drop it in the +down+ method. It is wise to do things in precisely the reverse order to in the +up+ method. For example
+The +down+ method of your migration should revert the transformations done by the +up+ method. In other words, the database schema should be unchanged if you do an +up+ followed by a +down+. For example, if you create a table in the +up+ method, you should drop it in the +down+ method. It is wise to reverse the transformations in precisely the reverse order they were made in the +up+ method. For example,
 
 <ruby>
 class ExampleMigration < ActiveRecord::Migration
@@ -402,22 +402,22 @@ class ExampleMigration < ActiveRecord::Migration
 end
 </ruby>
 
-Sometimes your migration will do something which is just plain irreversible, for example it might destroy some data. In cases like those when you can't reverse the migration you can raise +ActiveRecord::IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration an error message will be displayed saying that it can't be done.
+Sometimes your migration will do something which is just plain irreversible; for example, it might destroy some data. In such cases, you can raise +ActiveRecord::IrreversibleMigration+ from your +down+ method. If someone tries to revert your migration, an error message will be displayed saying that it can't be done.
 
 h3. Running Migrations
 
-Rails provides a set of rake tasks to work with migrations which boils down to running certain sets of migrations. The very first migration related rake task you use will probably be +db:migrate+. In its most basic form it just runs the +up+ method for all the migrations that have not yet been run. If there are no such migrations it exits.
+Rails provides a set of rake tasks to work with migrations which boil down to running certain sets of migrations. The very first migration related rake task you will use will probably be +db:migrate+. In its most basic form it just runs the +up+ method for all the migrations that have not yet been run. If there are no such migrations, it exits.
 
 Note that running the +db:migrate+ also invokes the +db:schema:dump+ task, which will update your db/schema.rb file to match the structure of your database.
 
 If you specify a target version, Active Record will run the required migrations (up or down) until it has reached the specified version. The
-version is the numerical prefix on the migration's filename. For example to migrate to version 20080906120000 run
+version is the numerical prefix on the migration's filename. For example, to migrate to version 20080906120000 run
 
 <shell>
 $ 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.
+If version 20080906120000 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.
 
 h4. Rolling Back
 
@@ -435,13 +435,13 @@ $ rake db:rollback STEP=3
 
 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
+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
 </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.
+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.
 
 Lastly, the +db:reset+ task will drop the database, recreate it and load the current schema into it.
 
@@ -449,7 +449,7 @@ NOTE: This is not the same as running all the migrations - see the section on "s
 
 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
+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
@@ -511,11 +511,11 @@ generates the following output
 20080906170109 CreateProducts: migrated (10.0097s)
 </shell>
 
-If you just want Active Record to shut up then running +rake db:migrate VERBOSE=false+ will suppress all output.
+If you just want Active Record to shut up, then running +rake db:migrate VERBOSE=false+ will suppress all output.
 
 h3. Using Models in Your Migrations
 
-When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done, but some caution should be observed.
+When creating or updating data in a migration it is often tempting to use one of your models. After all, they exist to provide easy access to the underlying data. This can be done, but some caution should be observed.
 
 For example, problems occur when the model uses database columns which are (1) not currently in the database and (2) will be created by this or a subsequent migration.
 
@@ -524,7 +524,7 @@ Consider this example, where Alice and Bob are working on the same code base whi
 Bob goes on vacation.
 
 Alice creates a migration for the +products+ table which adds a new column and initializes it.
-She also adds a validation to the Product model for the new column.
+She also adds a validation to the +Product+ model for the new column.
 
 <ruby>
 # db/migrate/20100513121110_add_flag_to_product.rb
@@ -545,7 +545,7 @@ class Product < ActiveRecord::Base
 end
 </ruby>
 
-Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the Product model for the new column.
+Alice adds a second migration which adds and initializes another column to the +products+ table and also adds a validation to the +Product+ model for the new column.
 
 <ruby>
 # db/migrate/20100515121110_add_fuzz_to_product.rb
@@ -573,7 +573,7 @@ Bob comes back from vacation and:
 # updates the source - which contains both migrations and the latests version of the Product model.
 # runs outstanding migrations with +rake db:migrate+, which includes the one that updates the +Product+ model.
 
-The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs.
+The migration crashes because when the model attempts to save, it tries to validate the second added column, which is not in the database when the _first_ migration runs:
 
 <plain>
 rake aborted!
@@ -584,7 +584,7 @@ undefined method `fuzz' for #<Product:0x000001049b14a0>
 
 A fix for this is to create a local model within the migration. This keeps rails from running the validations, so that the migrations run to completion.
 
-When using a faux model, it's a good idea to call +Product.reset_column_information+ to refresh the ActiveRecord cache for the Product model prior to updating data in the database.
+When using a faux model, it's a good idea to call +Product.reset_column_information+ to refresh the +ActiveRecord+ cache for the +Product+ model prior to updating data in the database.
 
 If Alice had done this instead, there would have been no problem:
 
@@ -654,13 +654,11 @@ ActiveRecord::Schema.define(:version => 20080906171750) do
 end
 </ruby>
 
-In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using +create_table+, +add_index+, and so on. Because this is database independent it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.
+In many ways this is exactly what it is. This file is created by inspecting the database and expressing its structure using +create_table+, +add_index+, and so on. Because this is database-independent, it could be loaded into any database that Active Record supports. This could be very useful if you were to distribute an application that is able to run against multiple databases.
 
-There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this then you should set the schema format to +:sql+.
+There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
 
-Instead of using Active Record's schema dumper the database's structure will be dumped using a tool specific to that database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example for PostgreSQL the +pg_dump+ utility is used and for MySQL this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading this schema is simply a question of executing the SQL statements contained inside.
-
-By definition this will be a perfect copy of the database's structure but this will usually prevent loading the schema into a database other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific the RDBMS of the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
 
 h4. Schema Dumps and Source Control
 
@@ -670,6 +668,6 @@ h3. Active Record and Referential Integrity
 
 The Active Record way claims that intelligence belongs in your models, not in the database. As such, features such as triggers or foreign key constraints, which push some of that intelligence back into the database, are not heavily used.
 
-Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
+Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level, these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
 
 Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
-- 
cgit v1.2.3


From ea49935a6e0eca8783bc8d1bb46a6c518c073cac Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Wed, 5 Oct 2011 18:40:45 +0530
Subject: copy editing

---
 railties/guides/source/migrations.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index a73655d130..9c92d567d3 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
 
 There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
 
-Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific the RDBMS of the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
 
 h4. Schema Dumps and Source Control
 
-- 
cgit v1.2.3


From d4ea804e21695416a2473ef96ff73e06b74b24a0 Mon Sep 17 00:00:00 2001
From: mhutchin <mike@mhutchinson.com>
Date: Fri, 7 Oct 2011 08:16:33 -0700
Subject: Replace the reference to the annotate_models plugin (unchanged since
 2008) with more current annotate_models gem

---
 railties/guides/source/migrations.textile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 9c92d567d3..ec812f9e13 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,7 +628,11 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
 
 For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
 
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations but is all summed up in the schema file. The "annotate_models":http://agilewebdevelopment.com/plugins/annotate_models plugin, which automatically adds (and updates) comments at the top of each model summarizing the schema, may also be of interest.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is
+frequently spread across several migrations, but is summed up in the schema
+file. The "annotate_models":http://github.com/ctran/annotate_models
+gem automatically adds and updates comments at the top of each model summarizing
+the schema if you desire that functionality.
 
 h4. Types of Schema Dumps
 
-- 
cgit v1.2.3


From fca2613ec444face807dc3aecf0d8b59acf30eae Mon Sep 17 00:00:00 2001
From: mhutchin <mike@mhutchinson.com>
Date: Fri, 7 Oct 2011 08:26:05 -0700
Subject: Correct formatting

---
 railties/guides/source/migrations.textile | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index ec812f9e13..6ec4d7f70e 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,11 +628,7 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
 
 For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
 
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is
-frequently spread across several migrations, but is summed up in the schema
-file. The "annotate_models":http://github.com/ctran/annotate_models
-gem automatically adds and updates comments at the top of each model summarizing
-the schema if you desire that functionality.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":http://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
 
 h4. Types of Schema Dumps
 
-- 
cgit v1.2.3


From cb244f4f70dbc22813e78e58f6a63392462417f7 Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Fri, 7 Oct 2011 22:19:55 +0530
Subject: use https for github url

---
 railties/guides/source/migrations.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 6ec4d7f70e..23e36b39f9 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -628,7 +628,7 @@ There is no need (and it is error prone) to deploy a new instance of an app by r
 
 For example, this is how the test database is created: the current development database is dumped (either to +db/schema.rb+ or +db/development.sql+) and then loaded into the test database.
 
-Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":http://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
+Schema files are also useful if you want a quick look at what attributes an Active Record object has. This information is not in the model's code and is frequently spread across several migrations, but is summed up in the schema file. The "annotate_models":https://github.com/ctran/annotate_models gem automatically adds and updates comments at the top of each model summarizing the schema if you desire that functionality.
 
 h4. Types of Schema Dumps
 
-- 
cgit v1.2.3


From 9b534060bfafbf1db36e73bb3e538b8c412dcc54 Mon Sep 17 00:00:00 2001
From: Vijay Dev <vijaydev.cse@gmail.com>
Date: Fri, 18 Nov 2011 01:17:21 +0530
Subject: update guide: db:structure:dump produces structure.sql now

---
 railties/guides/source/migrations.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 23e36b39f9..5b52a93853 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -658,7 +658,7 @@ In many ways this is exactly what it is. This file is created by inspecting the
 
 There is however a trade-off: +db/schema.rb+ cannot express database specific items such as foreign key constraints, triggers, or stored procedures. While in a migration you can execute custom SQL statements, the schema dumper cannot reconstitute those statements from the database. If you are using features like this, then you should set the schema format to +:sql+.
 
-Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/#{Rails.env}_structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
+Instead of using Active Record's schema dumper, the database's structure will be dumped using a tool specific to the database (via the +db:structure:dump+ Rake task) into +db/structure.sql+. For example, for the PostgreSQL RDBMS, the +pg_dump+ utility is used. For MySQL, this file will contain the output of +SHOW CREATE TABLE+ for the various tables. Loading these schemas is simply a question of executing the SQL statements they contain. By definition, this will create a perfect copy of the database's structure. Using the +:sql+ schema format will, however, prevent loading the schema into a RDBMS other than the one used to create it.
 
 h4. Schema Dumps and Source Control
 
-- 
cgit v1.2.3


From 6d05c793cafe79860bcbb469d6c46c83c531ab34 Mon Sep 17 00:00:00 2001
From: Rodrigo Rosenfeld Rosas <rr.rosas@gmail.com>
Date: Mon, 28 Nov 2011 13:15:07 -0200
Subject: Update information about foreign key plugins support in the guides

There is not "a number" of up-to-date maintained plugins for dealing with foreign keys.

The foreign_key_migrations does not have any update since 2009 and is also about to be removed:

Extracted from http://www.harukizaemon.com/2009/09/plugins-grab-em-while-theyre-stale.html,
referenced in the plugin reference of the old guide version:

"And so it is that I will very shortly (within the next month) delete most of the plugins from
my GitHub account (harukizaemon)"
---
 railties/guides/source/migrations.textile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/guides/source/migrations.textile')

diff --git a/railties/guides/source/migrations.textile b/railties/guides/source/migrations.textile
index 5b52a93853..c63f2aa119 100644
--- a/railties/guides/source/migrations.textile
+++ b/railties/guides/source/migrations.textile
@@ -670,4 +670,4 @@ The Active Record way claims that intelligence belongs in your models, not in th
 
 Validations such as +validates :foreign_key, :uniqueness => true+ are one way in which models can enforce data integrity. The +:dependent+ option on associations allows models to automatically destroy child objects when the parent is destroyed. Like anything which operates at the application level, these cannot guarantee referential integrity and so some people augment them with foreign key constraints.
 
-Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. There are also a number of plugins such as "foreign_key_migrations":https://github.com/harukizaemon/redhillonrails/tree/master/foreign_key_migrations/ which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
+Although Active Record does not provide any tools for working directly with such features, the +execute+ method can be used to execute arbitrary SQL. You could also use some plugin like "foreigner":https://github.com/matthuhiggins/foreigner which add foreign key support to Active Record (including support for dumping foreign keys in +db/schema.rb+).
-- 
cgit v1.2.3

