diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-09 15:46:29 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-09 15:46:29 +0000 |
commit | 47a3bafe26fb5f773ac082162c3e595ce80d9ad7 (patch) | |
tree | 1574a44c26b5f1102cd96b188933728289f7c7cb /activerecord/lib | |
parent | 8266867881e708813eec3c359869d14098e3789d (diff) | |
download | rails-47a3bafe26fb5f773ac082162c3e595ce80d9ad7.tar.gz rails-47a3bafe26fb5f773ac082162c3e595ce80d9ad7.tar.bz2 rails-47a3bafe26fb5f773ac082162c3e595ce80d9ad7.zip |
Added a VERSION parameter to the migrate task that allows you to do "rake migrate VERSION=34" to migrate to the 34th version traveling up or down depending on the current version. Added ActiveRecord::Migrator.migrate that can figure out whether to go up or down based on the target version and the current
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1780 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 365f57f366..a71e367ef2 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -108,6 +108,18 @@ module ActiveRecord # add_column :items, :completed_items_count # end # end + # + # And some times you need to do something in SQL not abstracted directly by migrations: + # + # class MakeJoinUnique < ActiveRecord::Migration + # def self.up + # execute "ALTER TABLE `pages_linked_pages` ADD UNIQUE `page_id_linked_page_id` (`page_id`,`linked_page_id`)" + # end + # + # def self.down + # execute "ALTER TABLE `pages_linked_pages` DROP INDEX `page_id_linked_page_id`" + # end + # end class Migration class << self def up() end @@ -122,6 +134,17 @@ module ActiveRecord class Migrator#:nodoc: class << self + def migrate(migrations_path, target_version = nil) + case + when target_version.nil?, current_version < target_version + up(migrations_path, target_version) + when current_version > target_version + down(migrations_path, target_version) + when current_version == target_version + return # You're on the right version + end + end + def up(migrations_path, target_version = nil) self.new(:up, migrations_path, target_version).migrate end |