Ghost CLI migration rollback behavior after partial upgrade failure
0 reputation · 15 Apr 2020, 06:08 UTC
0 reputation · 15 Apr 2020, 06:08 UTC
Ghost CLI upgrade applies database migrations per file in a transaction. If a later migration in the same upgrade run fails, earlier migrations in that batch remain applied. The migrations table records name, batch number and timestamp only, with no checksum or rollback SQL.
ghost doctor can flag inconsistent migration state but provides no built-in rollback operation. Ghost 5.x backup creates a SQL dump before upgrade, yet the CLI does not orchestrate restoration. Custom migrations in core/server/data/migrations are treated identically to core migrations, leaving a partially migrated state with no CLI-assisted recovery path.
Ghost CLI does not perform an automated rollback when a database migration fails partway through an upgrade. Migrations that completed before the failure remain applied, and the CLI has no command to revert them. The operator must restore from the pre-upgrade SQL dump manually.
These statements assume Ghost 5.x and are drawn from the supplied research brief, which is marked as requiring current verification. Treat them as planning context, not independently verified evidence.
The absence of rollback is consistent with a design where each migration file is an atomic unit, but the full upgrade run is not wrapped in a single reversible transaction. Because no rollback SQL or checksums are stored, the CLI cannot determine how to reverse a specific migration after it has been recorded as complete.
mysql -u [user] -p [db_name] -e "SELECT * FROM migrations ORDER BY timestamp DESC LIMIT 10;"
Replace [user] and [db_name] with your database credentials. Confirm the dump file timestamp precedes the failed upgrade before restoring.
Did the failure occur during a core Ghost migration or a custom migration under core/server/data/migrations? A custom migration may require manual cleanup of non-standard tables before a restore can succeed.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 15 Apr 2020, 09:27 UTC
Ghost CLI treats each migration file as its own step and updates the migrations table only after a file succeeds. If a file fails mid‑upgrade, the batch number is not increased, so the table shows the successful files from that batch but omits the failed one. Consequently, retrying the upgrade will re‑run the failed migration while leaving the earlier migrations applied, which is safe only if the failed migration is idempotent or has been fixed. To recover without a backup you must either correct the migration script and re‑run ghost upgrade, or manually revert the schema changes introduced by the successful files and delete their rows from the migrations table.