提交 16dadb12 编写于 作者: C Chris Arcand

Make 'migrate' clear the schema cache afterward

Without clearing the caches afterward, removals done in migrations would
not be reflected in a separate task in the same process. That is, given
a table with a migration to remove a column, the schema cache would
still reflect that a table has that in something such as the
'db:seed' task:

`rake db:migrate db:seed`
(A common thing to do in a script for a project ala `bin/setup`)

vs

`rake db:migrate && rake db:seed`
(Two processes)

The first would not reflect that the column was removed.
The second would (cache reset).
上级 2e8a350c
......@@ -159,6 +159,7 @@ def migrate
Migrator.migrate(migrations_paths, version) do |migration|
scope.blank? || scope == migration.scope
end
ActiveRecord::Base.clear_cache!
ensure
Migration.verbose = verbose_was
end
......
......@@ -309,19 +309,30 @@ def test_drops_testand_development_databases_when_rails_env_is_development
end
class DatabaseTasksMigrateTest < ActiveRecord::TestCase
def setup
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path'
end
def teardown
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil
end
def test_migrate_receives_correct_env_vars
verbose, version = ENV['VERBOSE'], ENV['VERSION']
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = 'custom/path'
ENV['VERBOSE'] = 'false'
ENV['VERSION'] = '4'
ActiveRecord::Migrator.expects(:migrate).with('custom/path', 4)
ActiveRecord::Tasks::DatabaseTasks.migrate
ensure
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = nil
ENV['VERBOSE'], ENV['VERSION'] = verbose, version
end
def test_migrate_clears_schema_cache_afterward
ActiveRecord::Base.expects(:clear_cache!)
ActiveRecord::Tasks::DatabaseTasks.migrate
end
end
class DatabaseTasksPurgeTest < ActiveRecord::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册