fix: verify server snapshots and recover whole migration sessions (#3)
This commit is contained in:
1 parent
3d4101ecc0
commit
8569871a17
29 files changed
+1923
-133
No files matched your search
@@ -0,0 +1,62 @@
|
||||
# Decision: verified snapshots and whole-session recovery for server migrations
|
||||
|
||||
**Date:** 2026-10-26
|
||||
**Status:** active
|
||||
|
||||
## Context
|
||||
|
||||
Issue #3 fixes FK error propagation, session variables and verify execution.
|
||||
Its proposed manual-backup exception conflicts with the shared go-database
|
||||
contract. MariaDB DDL cannot be made rollback-safe by wrapping the migration
|
||||
files in an ordinary transaction: see [MariaDB implicit commits](https://mariadb.com/docs/server/reference/sql-statements/transactions/sql-statements-that-cause-an-implicit-commit).
|
||||
|
||||
## Decision
|
||||
|
||||
The migration engine, rather than the operator, owns full-session and pre-file
|
||||
per-table backups. A Go ZIP/JSON snapshot format avoids external database-client
|
||||
dependencies. Every archive is restored into a temporary schema and compared
|
||||
before the corresponding original-schema changes. Per-file archives include all
|
||||
tables to cover incomplete legacy affected-table headers and dynamic SQL.
|
||||
|
||||
On failure, restore each step snapshot in reverse order; use the full-session
|
||||
snapshot as fallback. Include migration history in recovery. Persist a recovery
|
||||
marker before applying any changes, refuse an interrupted session on retry and
|
||||
ship an explicit `-migrate-restore` path. Restore failures retain archives and
|
||||
produce diagnostics instead of claiming success.
|
||||
|
||||
The production dump contains 27 triggers, so the implementation preserves
|
||||
InnoDB tables and trigger bodies, definers, order and SQL/charset context.
|
||||
Triggers are recreated after row loading to avoid firing them during restore;
|
||||
verification binds them to the temporary schema and performs no later DML.
|
||||
Views, routines, events, cross-schema FKs and legacy trigger/database collation
|
||||
mismatches are refused before changes. It requires an existing
|
||||
DBA account with directly granted global ALL PRIVILEGES so object/client
|
||||
visibility cannot silently hide unsupported state, plus a maintenance window
|
||||
without other writers. Do not grant these privileges to the runtime user. The
|
||||
advisory migration lock excludes other runners, not arbitrary SQL clients.
|
||||
|
||||
The parser supports SQL literals and quoted identifiers containing semicolons,
|
||||
escaped/doubled quotes and ordinary comments. It rejects malformed input,
|
||||
executable comments and DELIMITER rather than silently misinterpreting them.
|
||||
Existing merged SQL files are unchanged.
|
||||
|
||||
## Consequences
|
||||
|
||||
Safety snapshots and restore verification add disk usage, temporary server schema
|
||||
creation and runtime to the developer-only migration command. Normal local-first
|
||||
CRUD and sync gain no MariaDB dependency. Migration commands start no background
|
||||
connection worker. Before production use, rehearse on a current production dump
|
||||
in MariaDB matching production version and collation; synthetic tests alone do
|
||||
not satisfy that gate. Unsupported schema features need explicit recovery support
|
||||
before such schemas may be migrated by this tool.
|
||||
|
||||
## Acceptance
|
||||
|
||||
Rehearsed on the supplied 2026-10-26 production dump (45 tables, 27 triggers),
|
||||
using an isolated MariaDB 11.8.3 container and utf8mb4_uca1400_ai_ci. The test
|
||||
verifies full restore, actual migration 035 on the reconstructed pre-035 clone,
|
||||
reverse recovery after a later DDL/verify failure, successful retry and exact
|
||||
restoration of the original dump state. Synthetic tests additionally exercise
|
||||
FK errno 150, interrupted-session recovery, NULL/empty/binary/decimal/timestamp
|
||||
values, zero auto-increment IDs and legacy zero dates. No production changes
|
||||
are performed by these checks.
|
||||
Reference in new issue
Block a user