Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3017

Show
Ignore:
Timestamp:
11/14/05 03:51:39 (3 years ago)
Author:
bitsweat
Message:

Update documentation for Migrations. References #2861.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r3001 r3017  
    11*SVN* 
     2 
     3* Update documentation for Migrations.  #2861 [Tom Werner <tom@cube6media.com>] 
    24 
    35* 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] 
  • trunk/activerecord/lib/active_record/migration.rb

    r2832 r3017  
    2121  #       add_column :accounts, :ssl_enabled, :boolean, :default => 1 
    2222  #     end 
    23   #    
     23  # 
    2424  #     def self.down 
    2525  #       remove_column :accounts, :ssl_enabled 
     
    2929  # This migration will add a boolean flag to the accounts table and remove it again, if you're backing out of the migration. 
    3030  # 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, 
    3232  # but may also contain regular Ruby code for generating data needed for the transformations. 
    3333  # 
     
    4343  #         t.column :position, :integer 
    4444  #       end 
    45   #    
     45  # 
    4646  #       SystemSetting.create :name => "notice", :label => "Use notice?", :value => 1 
    4747  #     end 
    48   #    
     48  # 
    4949  #     def self.down 
    5050  #       drop_table :system_settings 
     
    8080  # == Running migrations from within Rails 
    8181  # 
    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. 
    85100  # 
    86101  # == Database support 
    87102  # 
    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). 
    89105  # 
    90106  # == More examples 
     
    96112  #       Tag.find(:all).each { |tag| tag.destroy if tag.pages.empty? } 
    97113  #     end 
    98   #    
     114  # 
    99115  #     def self.down 
    100116  #       # not much we can do to restore deleted data 
     
    129145  #   end 
    130146  # 
    131   # == Using the class after changing table 
     147  # == Using a model after changing its table 
    132148  # 
    133149  # 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 
    135151  # after the new column was added. Example: 
    136152  # 
    137   #   class MakeJoinUnique < ActiveRecord::Migration 
     153  #   class AddPeopleSalary < ActiveRecord::Migration 
    138154  #     def self.up 
    139155  #       add_column :people, :salary, :integer 
     156  #       Person.reset_column_information 
    140157  #       Person.find(:all).each do |p| 
    141158  #         p.salary = SalaryCalculator.compute(p) 
    142159  #       end 
    143160  #     end 
    144   #   end   
     161  #   end 
    145162  class Migration 
    146163    class << self