dongzhong1891 2013-11-05 16:23
浏览 41

CakePHP:使用过滤器部署数据库更改

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:

  1. 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.
  2. Call the above component/query from inside the AppController's beforeFilter.
  3. Pull the changes into the live (with the above code in place).
  4. Wait a few seconds for the app to run once (either by another user or us).
  5. 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.

  • 写回答

2条回答 默认 最新

  • dongnaopa6200 2013-11-05 16:36
    关注

    Will something like this work?

    Sort of. You will likely still suffer downtime. Even if only briefly while the queries finish running. You may also have concurrency issues if the site has heavy traffic during your deployment.

    Is there a better way to do this that I'm missing?

    With a load balanced system you could update one system at a time while diverting traffic to another system until all systems are updated.

    You could feature flag your code. Code will not run until this feature is enabled. So launch your code and when your database updates are complete, enable the feature.

    What do I need to know about the model caches to keep from throwing errors.

    I am not familiar enough with caches, but cache could provide the illusion that the site is available. But any dynamic request (form submission) could still result in an error.

    As an aside, take a look at Schema Migrations if you haven't already.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀