diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-12-05 12:13:49 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-12-05 12:13:49 -0800 |
commit | 0c692f4d121792117b6a71e5ed590a31c3b9d12e (patch) | |
tree | 869bf3fb884e55847bf7aa34b4c6b463d1590720 /activerecord/lib/active_record/migration.rb | |
parent | 2e299fca715b083a60222a85e48f9d3b8dd8ce93 (diff) | |
parent | 94ef7b515b9bd026a0ed67ef7dabbf0b4ab554e3 (diff) | |
download | rails-0c692f4d121792117b6a71e5ed590a31c3b9d12e.tar.gz rails-0c692f4d121792117b6a71e5ed590a31c3b9d12e.tar.bz2 rails-0c692f4d121792117b6a71e5ed590a31c3b9d12e.zip |
Merge branch 'joshsusser-master' into merge
* joshsusser-master:
style cleanup
Add migration history to schema.rb dump
Add metadata to schema_migrations
Conflicts:
activerecord/CHANGELOG.md
activerecord/lib/active_record/schema.rb
Diffstat (limited to 'activerecord/lib/active_record/migration.rb')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 22347fcaef..4ce276d4bf 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -1,5 +1,6 @@ require "active_support/core_ext/class/attribute_accessors" require 'set' +require 'digest/md5' module ActiveRecord # Exception that can be raised to stop migrations from going backwards. @@ -554,6 +555,10 @@ module ActiveRecord delegate :migrate, :announce, :write, :to => :migration + def fingerprint + @fingerprint ||= Digest::MD5.hexdigest(File.read(filename)) + end + private def migration @@ -724,7 +729,7 @@ module ActiveRecord raise UnknownMigrationVersionError.new(@target_version) if target.nil? unless (up? && migrated.include?(target.version.to_i)) || (down? && !migrated.include?(target.version.to_i)) target.migrate(@direction) - record_version_state_after_migrating(target.version) + record_version_state_after_migrating(target) end end @@ -747,7 +752,7 @@ module ActiveRecord begin ddl_transaction do migration.migrate(@direction) - record_version_state_after_migrating(migration.version) + record_version_state_after_migrating(migration) end rescue => e canceled_msg = Base.connection.supports_ddl_transactions? ? "this and " : "" @@ -805,13 +810,18 @@ module ActiveRecord raise DuplicateMigrationVersionError.new(version) if version end - def record_version_state_after_migrating(version) + def record_version_state_after_migrating(target) if down? - migrated.delete(version) - ActiveRecord::SchemaMigration.where(:version => version.to_s).delete_all + migrated.delete(target.version) + ActiveRecord::SchemaMigration.where(:version => target.version.to_s).delete_all else - migrated << version - ActiveRecord::SchemaMigration.create!(:version => version.to_s) + migrated << target.version + ActiveRecord::SchemaMigration.create!( + :version => target.version.to_s, + :migrated_at => Time.now, + :fingerprint => target.fingerprint, + :name => File.basename(target.filename,'.rb').gsub(/^\d+_/,'') + ) end end |