aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails_generator/commands.rb13
-rw-r--r--railties/lib/tasks/databases.rake17
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.'