public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
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
jeremy (author)
Thu Dec 06 10:57:19 -0800 2007
commit  699da7001b9e3d35c282ab3eb5371ba668bdeaa3
tree    fa7000dedc893ebd54b0fdce07857f3946789f9d
parent  ee6232e6077b8178adf04626c0797594a673dcc2
...
350
351
352
 
 
 
 
353
354
355
...
350
351
352
353
354
355
356
357
358
359
0
@@ -350,6 +350,10 @@
0
       end
0
     end
0
 
0
+ def pending_migrations
0
+ migration_classes.select { |m| m.version > current_version }
0
+ end
0
+
0
     private
0
       def migration_classes
0
         migrations = migration_files.inject([]) do |migrations, migration_file|
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *2.0.0* (December 6th, 2007)
0
 
0
+* The test task stops with a warning if you have pending migrations. #10377 [Josh Knowles]
0
+
0
 * Add warning to documentation about using transactional fixtures when the code under test uses transactions itself. Closes #7548 [thijsv]
0
 
0
 * Update Prototype to 1.6.0.1. [sam]
...
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
128
129
130
...
290
291
292
293
 
294
295
296
...
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
...
303
304
305
 
306
307
308
309
0
@@ -125,6 +125,19 @@
0
     puts "Current version: #{ActiveRecord::Migrator.current_version}"
0
   end
0
 
0
+ desc "Raises an error if there are pending migrations"
0
+ task :abort_if_pending_migrations => :environment do
0
+ pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
0
+
0
+ if pending_migrations.any?
0
+ puts "You have #{pending_migrations.size} pending migrations:"
0
+ pending_migrations.each do |pending_migration|
0
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
0
+ end
0
+ abort "Run `rake db:migrate` to update your database then try again."
0
+ end
0
+ end
0
+
0
   namespace :fixtures do
0
     desc "Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y"
0
     task :load => :environment do
0
@@ -290,7 +303,7 @@
0
     end
0
 
0
     desc 'Prepare the test database and load the schema'
0
- task :prepare => :environment do
0
+ task :prepare => %w(environment db:abort_if_pending_migrations) do
0
       if defined?(ActiveRecord::Base) && !ActiveRecord::Base.configurations.blank?
0
         Rake::Task[{ :sql => "db:test:clone_structure", :ruby => "db:test:clone" }[ActiveRecord::Base.schema_format]].invoke
0
       end

Comments

    No one has commented yet.