Do you use ORM for data access layer? I know that Doctrine comes with a transition API that allows you to switch versions up and down (in case something went wrong with the new version).
Outside of any ORM structure or consideration, a fast script minimizes slowdown (or downtime if the process is too long).
In my opinion, I would rather interrupt access to the website for 30 seconds with an information page than getting a shorter interception time, but getting visible errors or no display at all. If interruption time matters, it is best to do this at night or with less traffic.
This can be done in one script (or, at least, launched by one command line), when we will do such scripts, we include a script in the shell:
- placing the application in standby mode (temporary static page): you can use the .htaccess redirection or whatever applies to your application / server environment.
- svn udpate (or switch) for updating source code and assets
- empty caches, clearing temporary files, etc.
- rebuild generated classes (symfony specific)
- update database structure with ALTER / CREATE TABLE queries
- if necessary, transfer data from the old structure to the new one: depending on what you changed in structure, you may need to select data before changing the database structure or using tmp tables.
- If everything went well, delete the temporary page. Update completed
- If something went wrong, display a red message to the operator so that he can see what happened, try to fix it, and then delete the wait page manually.
The script should run checks at every step and stop the first error, and it should be detailed (but concise) about what it does at all stages, so you can quickly fix the application if something goes wrong. The best restored script would be (error in step 2 - stopping the process - manual correction - recovery in step 3), I still did not find the time to implement it this way.
If it works very well, but this type of script should be intensively tested, as close as possible to the production environment. In general, we develop such scripts locally and test them on the same platform as in production env (only different paths and DBs)
If the wait page is not an option, you can go without it, but you need to ensure data and user integrity. As an example, use LOCK for tables during data update / transfer and use exclusive locks for modified files (I think SVN)
There may be other better solutions, but basically this is what I use and it does the work for us. The main drawback is that the script type had to be rewritten in each major release, which prompts me to look for other options for this, but which one? I would be glad if someone had a better and simpler alternative.
Benoit
source share