-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Make schema cache methods behave consistently #43105
Make schema cache methods behave consistently #43105
Conversation
Makes sense to me 👍 . |
In rails#43075 I added the ability to skip adding a configured set of tables to the schema cache. After pushing that PR I found the behavior across methods and database adapters to be inconsistent when a table didn't exist. Since ignored tables should behave the same as missing tables, I wanted to make the behavior consistent. Previously the behavior was: *mysql* columns & columns_hash: Raised db error for non-existent table primary_keys: returned `nil` for non-existent table indexes: Raised db error for non-existent table *sqlite3* columns & columns_hash: Raised db error for non-existent table primary_keys: returned `nil` for non-existent table indexes: returned `[]` for non-existent table *postgresql* columns & columns_hash: Raised db error for non-existent table primary_keys: returned `nil` for non-existent table indexes: returned `[]` for non-existent table Current behavior: *mysql, sqlite3, and postgresql* columns & columns_hash: Raise db error for non-existent table primary_keys: returns `nil` for non-existent table indexes: returns `[]` for non-existent table The only change is to mysql, which used to raise for indexes, now it returns and empty array like all the other adapters.
15afbfd
to
e323e68
Compare
After pushing this I found Now the behavior is: columns and columns_hash: all adapters raise for missing table In a future time I think there is a lot of room for improvement in the schema cache, but for today I'm aiming to unblock #43075. I will be offline until Sept 27, please revert this and #43075 if any issues occur. |
In cases where an application uses pt-osc or lhm they may have temporary tables being used for migrations. Those tables shouldn't be included by the schema cache because it makes the cache bigger and those tables shouldn't ever be queried by the application. This feature allows applications to configure a list of or regex of tables to ignore. The behavior for ignored tables for each method in the schema cache (`columns`, `columns_hash`, `primary_keys`, and `indexes`) matches the behavior of a non-existent table. `columns` and `columns_hash` will raise a database not found error, `primary_keys` will return `nil`. and `indexes` will return an empty array. See rails#43105 which make behavior across adapters consistent. To use in an application configure `config.active_record.schema_cache_ignored_tables` to an array of tables or regex's. Those tables will not be included in the schema cache dump.
In #43075 I added the ability to skip adding a configured set of tables
to the schema cache. After pushing that PR I found the behavior across
methods and database adapters to be inconsistent when a table didn't exist.
Since ignored tables should behave the same as missing tables, I wanted
to make the behavior consistent.
Previously the behavior was:
mysql
columns & columns_hash: Raised db error for non-existent table
primary_keys: returned
nil
for non-existent tableindexes: Raised db error for non-existent table
sqlite3
columns & columns_hash: Raised db error for non-existent table
primary_keys: returned
nil
for non-existent tableindexes: returned
[]
for non-existent tablepostgresql
columns & columns_hash: Raised db error for non-existent table
primary_keys: returned
nil
for non-existent tableindexes: returned
[]
for non-existent tableCurrent behavior:
mysql, sqlite3, and postgresql
columns & columns_hash: Raise db error for non-existent table
primary_keys: returns
nil
for non-existent tableindexes: returns
[]
for non-existent tableThe only change is to mysql, which used to raise for indexes, now it
returns and empty array like all the other adapters.
cc/ @tenderlove we chatted about this
cc/ @rafaelfranca @casperisfine how do you all feel about this?