We periodically need to modify the structure of our production database. In many cases, these changes correspond to changes in the codebase which reference the new changes.
We usually end up putting up a fail whale page for a minute while we pull the new changes and run the new SQL queries, but I'm interested in writing a component or something to run the SQL queries on the fly, so that no downtime would be required.
I haven't tried it yet, but here's my plan:
- Write a component or something to run a specific query or queries. The queries will probably have checks like
IF EXISTS
so they run only once. I think it will also have to clear the model / persistent caches too. - Call the above component/query from inside the AppController's
beforeFilter
. - Pull the changes into the live (with the above code in place).
- Wait a few seconds for the app to run once (either by another user or us).
- Remove the beforeFilter code which triggered the SQL queries to run.
Is this a crazy idea? Here's my questions: A. Will something like this work? B. Is there a better way to do this that I'm missing? C. What do I need to know about the model caches to keep from throwing errors. Presumably, the debug level will be set to 0 (because the site will be in production).
By the way, it seems relevant to mention that we are not on a load balanced system. We're on a single dedicated server.