-
Notifications
You must be signed in to change notification settings - Fork 162
Open
Description
Adding a new field to a cached model causes an error on deployment because our code expects the new field to exist (ProgrammingError: column example_abc does not exist). Of course, the new field does not exist in previously-cached objects.
Any recommendations on how to handle schema migrations with Cache Machine?
A few ideas come to mind:
- Invalidate the entire cache when the schema changes. Not ideal because it's far too broad and can cause a run on the DB for high-traffic sites.
- Track all the queries associated with a given table and invalidate only those associated with a model. Better than clearing the whole cache, but this comes with the overhead of maintaining the flush lists of queries for a table and can still cause a run on the DB.
- Create middleware that invalidates individual cached queries/objects when a migration-related error occurs. E.g., on a
ProgrammingError, delete any cached query and retry the query. This feels clunky because any definition of "migration-related error" will probably be imprecise. - Do some cache warming. After a schema migration, instead of invalidating the cache, pull from the DB to update each cached query, and deploy when that's done. This seems like the best option, though it adds complexity and time to deployment.
Thoughts?
pikhovkin and Allan-Nava
Metadata
Metadata
Assignees
Labels
No labels