diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-05 17:56:46 +0900 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-06-05 17:56:46 +0900 |
commit | 3970432fcb6a04e6f003e8295e9b2ee8e5b22390 (patch) | |
tree | 999c449042d8a6ae27068c9f1c472d74620ca35f /activerecord | |
parent | 8ae73f11469e12d5f3f119189a4733a3a25ca785 (diff) | |
download | rails-3970432fcb6a04e6f003e8295e9b2ee8e5b22390.tar.gz rails-3970432fcb6a04e6f003e8295e9b2ee8e5b22390.tar.bz2 rails-3970432fcb6a04e6f003e8295e9b2ee8e5b22390.zip |
only check pending migrations if there are new files
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 20505d8f08..bce4802d0a 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -357,10 +357,15 @@ module ActiveRecord 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 @@ -698,6 +703,10 @@ module ActiveRecord File.basename(filename) end + def mtime + File.mtime filename + end + delegate :migrate, :announce, :write, :disable_ddl_transaction, to: :migration private @@ -713,6 +722,16 @@ module ActiveRecord 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 @@ -783,7 +802,11 @@ module ActiveRecord 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) |