aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorschneems <richard.schneeman@gmail.com>2016-01-11 11:58:12 -0600
committerschneems <richard.schneeman@gmail.com>2016-01-11 11:58:12 -0600
commit4d60e93174a3d6d90b1a06fc7515cb5cd749a6f3 (patch)
tree15b55ee18593a0c256510aeecde7eb07cb1b029c /activerecord/lib/active_record
parenta703999c62aa9950920bbc621aa332da337c68ca (diff)
downloadrails-4d60e93174a3d6d90b1a06fc7515cb5cd749a6f3.tar.gz
rails-4d60e93174a3d6d90b1a06fc7515cb5cd749a6f3.tar.bz2
rails-4d60e93174a3d6d90b1a06fc7515cb5cd749a6f3.zip
Set environment even when no migration runs
This PR addresses the issue described in https://github.com/rails/rails/pull/22967#issuecomment-170251635. If the database is non empty and has no new migrations than `db:migrate` will not set the environment. This PR works by always setting the environment value on successful `up` migration regardless of whether or not a migration was actually executed.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/migration.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb
index 471c5dc05a..8dedd4c8a2 100644
--- a/activerecord/lib/active_record/migration.rb
+++ b/activerecord/lib/active_record/migration.rb
@@ -1170,6 +1170,8 @@ module ActiveRecord
migration = migrations.detect { |m| m.version == @target_version }
raise UnknownMigrationVersionError.new(@target_version) if migration.nil?
execute_migration_in_transaction(migration, @direction)
+
+ record_environment
end
# Used for running multiple migrations up to or down to a certain value.
@@ -1181,6 +1183,14 @@ module ActiveRecord
runnable.each do |migration|
execute_migration_in_transaction(migration, @direction)
end
+
+ record_environment
+ end
+
+ # Stores the current environment in the database.
+ def record_environment
+ return if down?
+ ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
def ran?(migration)
@@ -1236,7 +1246,6 @@ module ActiveRecord
else
migrated << version
ActiveRecord::SchemaMigration.create!(version: version.to_s)
- ActiveRecord::InternalMetadata[:environment] = ActiveRecord::Migrator.current_environment
end
end