Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

only check pending migrations if there are new files

  • Loading branch information...
commit 1e1b49916a73573e074e27bc09129c00747da1d0 1 parent 15ff21a
@tenderlove tenderlove authored
Showing with 25 additions and 2 deletions.
  1. +25 −2 activerecord/lib/active_record/migration.rb
View
27 activerecord/lib/active_record/migration.rb
@@ -357,10 +357,15 @@ class Migration
class CheckPending
def initialize(app)
@app = app
+ @last_check = 0
end
def call(env)
- ActiveRecord::Migration.check_pending!
+ mtime = ActiveRecord::Migrator.last_migration.mtime.to_i
+ if @last_check < mtime
+ ActiveRecord::Migration.check_pending!
+ @last_check = mtime
+ end
@app.call(env)
end
end
@@ -697,6 +702,10 @@ def basename
File.basename(filename)
end
+ def mtime
+ File.mtime filename
+ end
+
delegate :migrate, :announce, :write, :disable_ddl_transaction, to: :migration
private
@@ -712,6 +721,16 @@ def load_migration
end
+ class NullMigration < MigrationProxy
+ def initialize(name, version, filename, scope)
+ super(nil, 0, nil, nil)
+ end
+
+ def mtime
+ 0
+ end
+ end
+
class Migrator#:nodoc:
class << self
attr_writer :migrations_paths
@@ -782,7 +801,11 @@ def needs_migration?
end
def last_version
- migrations(migrations_paths).last.try(:version)||0
+ last_migration.version
+ end
+
+ def last_migration # :nodoc:
+ migrations(migrations_paths).last || NullMigration.new
end
def proper_table_name(name)

0 comments on commit 1e1b499

Please sign in to comment.
Something went wrong with that request. Please try again.