Skip to content
This repository
Browse code

Update documentation for Migrations. References #2861.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3017 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit d8f5ccab1cf8c660849df299c1fe1ead58e83c95 1 parent 5cd2f32
Jeremy Kemper jeremy authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* Update documentation for Migrations. #2861 [Tom Werner <tom@cube6media.com>]
  4 +
3 5 * When AbstractAdapter#log rescues an exception, attempt to detect and reconnect to an inactive database connection. Connection adapter must respond to the active? and reconnect! instance methods. Initial support for PostgreSQL, MySQL, and SQLite. Make certain that all statements which may need reconnection are performed within a logged block: for example, this means no avoiding log(sql, name) { } if @logger.nil? [Jeremy Kemper]
4 6
5 7 * Much faster Oracle column reflection. #2848 [Michael Schoen <schoenm@earthlink.net>]
43 activerecord/lib/active_record/migration.rb
@@ -20,7 +20,7 @@ def initialize(version)
20 20 # def self.up
21 21 # add_column :accounts, :ssl_enabled, :boolean, :default => 1
22 22 # end
23   - #
  23 + #
24 24 # def self.down
25 25 # remove_column :accounts, :ssl_enabled
26 26 # end
@@ -28,7 +28,7 @@ def initialize(version)
28 28 #
29 29 # This migration will add a boolean flag to the accounts table and remove it again, if you're backing out of the migration.
30 30 # It shows how all migrations have two class methods +up+ and +down+ that describes the transformations required to implement
31   - # or remove the migration. These methods can consist of both the migration specific methods, like add_column and remove_column,
  31 + # or remove the migration. These methods can consist of both the migration specific methods, like add_column and remove_column,
32 32 # but may also contain regular Ruby code for generating data needed for the transformations.
33 33 #
34 34 # Example of a more complex migration that also needs to initialize data:
@@ -42,10 +42,10 @@ def initialize(version)
42 42 # t.column :type, :string
43 43 # t.column :position, :integer
44 44 # end
45   - #
  45 + #
46 46 # SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1
47 47 # end
48   - #
  48 + #
49 49 # def self.down
50 50 # drop_table :system_settings
51 51 # end
@@ -79,13 +79,29 @@ def initialize(version)
79 79 #
80 80 # == Running migrations from within Rails
81 81 #
82   - # The Rails package has support for migrations with the <tt>script/generate migration my_new_migration</tt> command and
83   - # with the <tt>rake migrate</tt> command that'll run all the pending migrations. It'll even create the needed schema_info
84   - # table automatically if it's missing.
  82 + # The Rails package has several tools to help create and apply migrations.
  83 + #
  84 + # To generate a new migration, use <tt>script/generate migration MyNewMigration</tt>
  85 + # where MyNewMigration is the name of your migration. The generator will
  86 + # create a file <tt>nnn_my_new_migration.rb</tt> in the <tt>db/migrate/</tt>
  87 + # directory, where <tt>nnn</tt> is the next largest migration number.
  88 + # You may then edit the <tt>self.up</tt> and <tt>self.down</tt> methods of
  89 + # n MyNewMigration.
  90 + #
  91 + # To run migrations against the currently configured database, use
  92 + # <tt>rake migrate</tt>. This will update the database by running all of the
  93 + # pending migrations, creating the <tt>schema_info</tt> table if missing.
  94 + #
  95 + # To roll the database back to a previous migration version, use
  96 + # <tt>rake migrate version=X</tt> where <tt>X</tt> is the version to which
  97 + # you wish to downgrade. If any of the migrations throw an
  98 + # <tt>IrreversibleMigration</tt> exception, that step will fail and you'll
  99 + # have some manual work to do.
85 100 #
86 101 # == Database support
87 102 #
88   - # Migrations are currently only supported in MySQL and PostgreSQL.
  103 + # Migrations are currently supported in MySQL, PostgreSQL, SQLite,
  104 + # SQL Server, and Oracle (all supported databases except DB2).
89 105 #
90 106 # == More examples
91 107 #
@@ -95,7 +111,7 @@ def initialize(version)
95 111 # def self.up
96 112 # Tag.find(:all).each { |tag| tag.destroy if tag.pages.empty? }
97 113 # end
98   - #
  114 + #
99 115 # def self.down
100 116 # # not much we can do to restore deleted data
101 117 # raise IrreversibleMigration
@@ -128,20 +144,21 @@ def initialize(version)
128 144 # end
129 145 # end
130 146 #
131   - # == Using the class after changing table
  147 + # == Using a model after changing its table
132 148 #
133 149 # Sometimes you'll want to add a column in a migration and populate it immediately after. In that case, you'll need
134   - # to make a call to Base#reset_column_information in order to ensure that the class has the latest column data from
  150 + # to make a call to Base#reset_column_information in order to ensure that the model has the latest column data from
135 151 # after the new column was added. Example:
136 152 #
137   - # class MakeJoinUnique < ActiveRecord::Migration
  153 + # class AddPeopleSalary < ActiveRecord::Migration
138 154 # def self.up
139 155 # add_column :people, :salary, :integer
  156 + # Person.reset_column_information
140 157 # Person.find(:all).each do |p|
141 158 # p.salary = SalaryCalculator.compute(p)
142 159 # end
143 160 # end
144   - # end
  161 + # end
145 162 class Migration
146 163 class << self
147 164 def up() end

0 comments on commit d8f5cca

Please sign in to comment.
Something went wrong with that request. Please try again.