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

Conversation

eileencodes
Copy link
Member

@eileencodes eileencodes commented Dec 15, 2021

I noticed this while debugging a separate issue locally. When
lazily_load_schema_cache is set to true AND there's a schema cache,
running db:drop twice will raise a no such table: schema_migrations
error. The problem here was that when check_protected_environments is
run before drop, the task checks for the latest environment. That check
looks at table_exists? defined in model_schema.rb. The issue is that
the model schema is checking connection.schema_cache.data_source_exists?.

When checking whether the environment is protected on schema migrations
we don't want to use the schema cache. We want to check the database
directly. The schema cache really is for the app after boot, so it's
safe to skip the schema cache in this area since we want to check the
database directly.

I noticed this while debugging a separate issue locally. When
`lazily_load_schema_cache` is set to true AND there's a schema cache,
running `db:drop` twice will raise a `no such table: schema_migrations`
error. The problem here was that when `check_protected_environments` is
run before drop, the task checks for the latest environment. That check
looks at `table_exists?` defined in `model_schema.rb`. The issue is that
the model schema is checking `connection.schema_cache.data_source_exists?`.

When checking whether the environment is protected or schema migrations
we don't want to use the schema cache. We want to check the database
directly. The schema cache really is for the app after boot, so it's
safe to skip the schema cache in this area since we want to check the
database directly.
@eileencodes
Copy link
Member Author

Note to self: this needs a backport to 7-0-stable.

@eileencodes eileencodes merged commit 0b990c4 into rails:main Dec 15, 2021
eileencodes added a commit that referenced this pull request Dec 15, 2021
…chema-migrations

Don't use schema cache when checking schema migrations
@eileencodes eileencodes deleted the dont-use-schema-cache-on-schema-migrations branch December 15, 2021 20:18
@eileencodes
Copy link
Member Author

Backported in 7d924ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant