aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorJeremy McNevin <jeremy.mcnevin@novu.com>2014-07-30 14:10:28 -0500
committerJeremy McNevin <jeremy.mcnevin@novu.com>2014-08-13 11:01:42 -0500
commit838e18321118ee3ec6669217e5ea0216f79c969a (patch)
tree894e8e98e16edb3ad1a43de20416dc8daad9d04a /activerecord/lib
parente9ce987a9a6fdad436b5511874963e8485b66f84 (diff)
downloadrails-838e18321118ee3ec6669217e5ea0216f79c969a.tar.gz
rails-838e18321118ee3ec6669217e5ea0216f79c969a.tar.bz2
rails-838e18321118ee3ec6669217e5ea0216f79c969a.zip
Correctly determine if migration is needed.
This method would assume that if last migration in the migrations directory matched the current schema version, that the database was up to date, but this does not account for new migrations with older timestamps that may be pending.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/migration.rb17
1 files changed, 8 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index a6847e28c2..659c5e3bbb 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -836,21 +836,20 @@ module ActiveRecord
SchemaMigration.table_name
end
- def get_all_versions
- SchemaMigration.all.map { |x| x.version.to_i }.sort
+ def get_all_versions(connection = Base.connection)
+ if connection.table_exists?(schema_migrations_table_name)
+ SchemaMigration.all.map { |x| x.version.to_i }.sort
+ else
+ []
+ end
end
def current_version(connection = Base.connection)
- sm_table = schema_migrations_table_name
- if connection.table_exists?(sm_table)
- get_all_versions.max || 0
- else
- 0
- end
+ get_all_versions(connection).max || 0
end
def needs_migration?(connection = Base.connection)
- current_version(connection) < last_version
+ (migrations(migrations_paths).collect(&:version) - get_all_versions(connection)).size > 0
end
def last_version