mirror of
https://github.com/github/rails.git
synced 2026-01-30 16:58:15 -05:00
The test task stops with a warning if you have pending migrations. Closes #10377.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8324 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -350,6 +350,10 @@ module ActiveRecord
|
||||
end
|
||||
end
|
||||
|
||||
def pending_migrations
|
||||
migration_classes.select { |m| m.version > current_version }
|
||||
end
|
||||
|
||||
private
|
||||
def migration_classes
|
||||
migrations = migration_files.inject([]) do |migrations, migration_file|
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
*2.0.0* (December 6th, 2007)
|
||||
|
||||
* The test task stops with a warning if you have pending migrations. #10377 [Josh Knowles]
|
||||
|
||||
* Add warning to documentation about using transactional fixtures when the code under test uses transactions itself. Closes #7548 [thijsv]
|
||||
|
||||
* Update Prototype to 1.6.0.1. [sam]
|
||||
|
||||
@@ -125,6 +125,19 @@ namespace :db do
|
||||
puts "Current version: #{ActiveRecord::Migrator.current_version}"
|
||||
end
|
||||
|
||||
desc "Raises an error if there are pending migrations"
|
||||
task :abort_if_pending_migrations => :environment do
|
||||
pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
|
||||
|
||||
if pending_migrations.any?
|
||||
puts "You have #{pending_migrations.size} pending migrations:"
|
||||
pending_migrations.each do |pending_migration|
|
||||
puts ' %4d %s' % [pending_migration.version, pending_migration.name]
|
||||
end
|
||||
abort "Run `rake db:migrate` to update your database then try again."
|
||||
end
|
||||
end
|
||||
|
||||
namespace :fixtures do
|
||||
desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
||||
task :load => :environment do
|
||||
@@ -290,7 +303,7 @@ namespace :db do
|
||||
end
|
||||
|
||||
desc 'Prepare the test database and load the schema'
|
||||
task :prepare => :environment do
|
||||
task :prepare => %w(environment db:abort_if_pending_migrations) do
|
||||
if defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
|
||||
Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user