Changeset 3017
- Timestamp:
- 11/14/05 03:51:39 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/migration.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r3001 r3017 1 1 *SVN* 2 3 * Update documentation for Migrations. #2861 [Tom Werner <tom@cube6media.com>] 2 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] trunk/activerecord/lib/active_record/migration.rb
r2832 r3017 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 … … 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 # … … 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 … … 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 … … 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 … … 129 145 # end 130 146 # 131 # == Using the class after changingtable147 # == 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 from150 # 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::Migration153 # 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