Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use schema cache when checking schema migrations #43877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/schema_migration.rb
Expand Up @@ -41,6 +41,10 @@ def normalized_versions
def all_versions
order(:version).pluck(:version)
end

def table_exists?
connection.data_source_exists?(table_name)
end
end

def version
Expand Down
22 changes: 22 additions & 0 deletions railties/test/application/rake/dbs_test.rb
Expand Up @@ -701,6 +701,28 @@ def db_fixtures_load(expected_database)
assert_equal("Not touched", File.read("db/schema.rb").strip)
end
end

test "lazily loaded schema cache isn't read when reading the schema migrations table" do
Dir.chdir(app_path) do
app_file "config/initializers/lazy_load_schema_cache.rb", <<-RUBY
Rails.application.config.active_record.lazily_load_schema_cache = true
RUBY

rails "generate", "model", "recipe", "title:string"
rails "db:migrate"
rails "db:schema:cache:dump"

file = File.read("db/schema_cache.yml")
assert_match(/schema_migrations: true/, file)
assert_match(/recipes: true/, file)

output = rails "db:drop"
assert_match(/Dropped database/, output)

repeat_output = rails "db:drop"
assert_match(/Dropped database/, repeat_output)
end
end
end
end
end