Why should the database script in the online upgrade be arranged in version order, and what should be done if it fails halfway
Why should the database scripts in the online upgrade be arranged in version order, because each script defaults to the previous one having been executed: a script adds a new field to the table, and the next one writes values to this field; if the order is reversed, the next one will not find the field and report an error directly; if it continues to run further, it will continue to rewrite the modified structure based on the old assumptions. As for what to do if it fails halfway, the correct treatment is to stop immediately and record the failed position in the log, rather than skipping the error and continuing to execute the remaining scripts - the more scripts that are executed, the greater the distance between the library structure and the program code, and the higher the cost of troubleshooting.
Why can't the order depend on anything other than the filename?
The upgrade script is essentially a time-accumulating dependency chain. Version A renamed the field, Version B built an index based on the new name, and Version C filled in data based on the new index.The program code reads the structure of the latest version, but the scripts are arranged according to their output time. The two can be aligned only by the order of execution. Therefore, placing the same batch of scripts in the same directory and running them in ascending order of version number is the premise for the establishment of this dependency chain.PbootCMS in the update records of V3.2.26 clearly stated this agreement: the upgrade SQL is unified in the script directory and executed in version order. The scripts scattered in the new equipment backup directory are only reserved for use in new installations.Separating the 'new installation' and 'upgrade' scripts is to avoid the installation SQL statements being mixed into the upgrade sequence and executed repeatedly.
What will be left out if you skip intermediate versions?
The most common problem during cross-version upgrade is not error, but the appearance of success. There are three common manifestations: fields are missing but the program reads the default value, the page displays normally, but the statistical data continues to deviate; the index is not built, the function is available but the query becomes slower and slower; old data is not filled back according to the new rules, and the口径 is inconsistent when the old and new content are displayed in the same place. This kind of state is difficult to deduce the cause from the phenomenon, because there is no error. A feasible approach is to let the upgrade program itself refuse to execute out of order: each time only allow continuous running from the current record version number, and stop asking when the version number is missing, rather than guessing from which entry to start.
Why stopping at failure is safer than continuing to run
The fixes for the program 'Tongxing Program V3.2.25' can explain this difference. The previous issue was that when the migration failed, it did not log, did not report errors to specific scripts, and the upgrade continued to the end, with the administrator seeing a successful prompt.The behavior after repair is to log the failure and stop the upgrade, while skipping pure comment fragments. The difference between the two methods lies in where the error remains: stopping at the first failure point, the library structure only progresses to that step, and when rolling back, it only needs to go back to the backup before the failure;If you keep running, the error will be scattered throughout each subsequent script, and by the time an exception is found, it's unclear at what step it began to deviate. Pure comment snippets should not be considered failures, as comments themselves do not change the structure; treating them as errors would stop a potentially normal upgrade, which is the reason it is separately explained in this repair record.
What order to handle after failure
| Stage | What to do first | Judgment basis | What actions to take next |
|---|---|---|---|
| Before upgrading | Make a complete backup | Both data and static files need to be overwritten, a missing item will result in an incomplete site after restoration | Note the current version number and script list |
| Fail at the moment | Read the log to locate the script | The log should specify which version and line the failure occurred in | Do not execute the entire batch script repeatedly |
| Repair period | Handle the failed script separately | Confirm whether it is a structural conflict, field already exists, or permission issue | Manually complete the version changes, and then continue with the subsequent versions |
| Restore | Return to the backup point | The structure cannot be aligned and cannot be repaired in the short term | Restore data and static files, and then schedule the next upgrade |
| Check | Verify section by section | Check the new field, index, and historical data backfill separately | Record the results, keep logs |
Check what needs to be verified before and after the upgrade
Before the upgrade, the backup needs to cover both data and static files. If only the database is backed up, the changes in the upload directory and template cannot be restored together. AnQiCMS (AnQi CMS) has made this a backend capability: backup and restore support data and static files, generate a backup in the background first before starting the script. The deployment form also affects the operation method, sites deployed with Baota panel or Docker image can leave an additional snapshot before the upgrade, and container mode is also convenient for rolling back to the previous image version.
The post-upgrade verification is carried out in three steps: check if the new fields and indexes are in place for the structural item; check if the historical content is filled in according to the new rules for the data item; check if the three main paths of list, detail, and form submission are normal for the behavioral item. The failure prompt should have a destination, and in-station support email reminders should be sent in advance to set up notification targets related to the upgrade, which is earlier than finding problems by reviewing logs after the fact. Clean up the temporary script files after verification to avoid being mistakenly treated as a pending item during the next upgrade.
Common questions
Question: Can the upgrade script be renamed to control the execution order?Answer: Renaming only affects file sorting and does not affect the version judgment in the script content. The order should be handed over to the upgrade program to decide according to the recorded version number. Manual renaming is easy to cause the record to be out of sync with the actual executed file.
Question: Can you ignore the error message saying that the field already exists?Answer: First, confirm whether this script has been executed. If it has indeed been executed, it means that the version number record does not match the actual structure, and the record should be corrected to the correct version before continuing; ignoring directly may skip over the truly unexecuted one.
Question: Can you rerun the entire batch of scripts after interruption?Answer: It depends on whether the script can be executed repeatedly. It can be used with the 'create if not exists' judgment, but will report an error if it is retried after directly creating a table or renaming. It is recommended to back up before re-running and judge each item in order from the failed position according to the log.