diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-28 21:21:01 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-28 21:21:01 +0000 |
commit | c00de99f69358b58ca2bd6bc732e2de1b667800e (patch) | |
tree | fd5d4855a64bb15a99494b7efdb62f4798321a52 /railties | |
parent | ad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19 (diff) | |
download | rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.tar.gz rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.tar.bz2 rails-c00de99f69358b58ca2bd6bc732e2de1b667800e.zip |
Switched to UTC-timebased version numbers for migrations and the schema. This will as good as eliminate the problem of multiple migrations getting the same version assigned in different branches. Also added rake db:migrate:up/down to apply individual migrations that may need to be run when you merge branches (closes #11458) [jbarnette]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9122 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails_generator/commands.rb | 13 | ||||
-rw-r--r-- | railties/lib/tasks/databases.rake | 17 |
2 files changed, 16 insertions, 14 deletions
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index 2f65918796..f74ca7722b 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -69,19 +69,8 @@ module Rails not existing_migrations(file_name).empty? end - def current_migration_number - Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path| - n = File.basename(file_path).split('_', 2).first.to_i - if n > max then n else max end - end - end - - def next_migration_number - current_migration_number + 1 - end - def next_migration_string(padding = 3) - "%.#{padding}d" % next_migration_number + Time.now.utc.strftime("%Y%m%d%H%M%S") end def gsub_file(relative_destination, regexp, *args, &block) diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 73259ee34d..bd96b23351 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -98,13 +98,26 @@ namespace :db do desc 'Resets your database using your migrations for the current environment' task :reset => ["db:drop", "db:create", "db:migrate"] + + desc 'Runs the "up" for a given migration VERSION.' + task :up => :environment do + version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil + raise "VERSION is required" unless version + ActiveRecord::Migrator.run(:up, "db/migrate/", version) + end + + desc 'Runs the "down" for a given migration VERSION.' + task :down => :environment do + version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil + raise "VERSION is required" unless version + ActiveRecord::Migrator.run(:down, "db/migrate/", version) + end end desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n' task :rollback => :environment do step = ENV['STEP'] ? ENV['STEP'].to_i : 1 - version = ActiveRecord::Migrator.current_version - step - ActiveRecord::Migrator.migrate('db/migrate/', version) + ActiveRecord::Migrator.rollback('db/migrate/', step) end desc 'Drops and recreates the database from db/schema.rb for the current environment.' |