aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2012-06-03 15:07:11 -0500
committerschneems <richard.schneeman@gmail.com>2012-06-03 15:07:11 -0500
commite5b39862cb4f8f3097cc8ab2dc606ddb1bd1febb (patch)
treefeee3d3ef6371b3e5207aa3087675db2b62c30d5 /activerecord/lib
parent0460949070d4105810d2c39e6e85fcf93034a861 (diff)
downloadrails-e5b39862cb4f8f3097cc8ab2dc606ddb1bd1febb.tar.gz
rails-e5b39862cb4f8f3097cc8ab2dc606ddb1bd1febb.tar.bz2
rails-e5b39862cb4f8f3097cc8ab2dc606ddb1bd1febb.zip
add convenience methods for checking migrations
if a rails project needs to be migrated ActiveRecord::Migrator.needs_migration? will be true or false if the current version matches the last version.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/migration.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index ac4f53c774..2975b045e7 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -605,6 +605,14 @@ module ActiveRecord
end
end
+ def needs_migration?
+ current_version != last_version
+ end
+
+ def last_version
+ migrations(migrations_paths).last.try(:version)||0
+ end
+
def proper_table_name(name)
# Use the Active Record objects own table_name, or pre/suffix from ActiveRecord::Base if name is a symbol/string
name.table_name rescue "#{ActiveRecord::Base.table_name_prefix}#{name}#{ActiveRecord::Base.table_name_suffix}"