mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 11:25:56 +00:00
Record update stages and migration results for support diagnosis
This commit is contained in:
1 parent
461fa035d0
commit
e8367354ef
3 files changed
+9
No files matched your search
@@ -187,6 +187,7 @@ pub fn apply_pending(store: &dyn Store, list: &[Migration], dir: &Path, snapshot
|
||||
}
|
||||
}
|
||||
let todo: Vec<&Migration> = list.iter().filter(|m| recorded(&rows, m).is_none_or(|r| r.status != Status::Applied)).collect();
|
||||
tracing::info!(total = list.len(), pending = todo.len(), skipped = list.len() - todo.len(), "database migration plan");
|
||||
|
||||
// Resolve and verify every file before running anything.
|
||||
let mut files = Vec::new();
|
||||
@@ -214,13 +215,16 @@ pub fn apply_pending(store: &dyn Store, list: &[Migration], dir: &Path, snapshot
|
||||
report.snapshot = Some(snapshot().map_err(|e| Error::Invalid(format!("No database update was applied because the safety backup failed: {e}")))?);
|
||||
}
|
||||
for (m, schema, path) in files {
|
||||
tracing::info!(migration = %m.id, database = %m.db, "database migration starting");
|
||||
store.put(&LedgerRow { db: m.db.clone(), id: m.id.clone(), sha256: m.sha256.clone(), status: Status::Running, error: Some("Interrupted SQL must be recovered before replay.".into()), baseline: false })?;
|
||||
match store.run_file(schema, &path) {
|
||||
Ok(()) => {
|
||||
store.put(&LedgerRow { db: m.db.clone(), id: m.id.clone(), sha256: m.sha256.clone(), status: Status::Applied, error: None, baseline: false })?;
|
||||
report.applied.push(m.id.clone());
|
||||
tracing::info!(migration = %m.id, database = %m.db, "database migration applied");
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!(migration = %m.id, database = %m.db, "database migration failed; details saved in migration history");
|
||||
let msg = e.to_string();
|
||||
let _ = store.put(&LedgerRow { db: m.db.clone(), id: m.id.clone(), sha256: m.sha256.clone(), status: Status::Failed, error: Some(msg.clone()), baseline: false });
|
||||
report.failed = Some((m.id.clone(), msg));
|
||||
|
||||
@@ -184,6 +184,7 @@ fn create_databases(root: &Path) -> Result<()> {
|
||||
let present = db.tables(schema)?;
|
||||
let missing: Vec<_> = tables.iter().filter(|table| !present.iter().any(|p| p == **table)).copied().collect();
|
||||
if !missing.is_empty() {
|
||||
tracing::error!(root = %root.display(), database = schema, missing_tables = ?missing, "Wildcard realm creation blocked by missing database tables");
|
||||
return Err(Error::Invalid(format!("Cannot create Wildcard: {schema} is missing tables: {}. Run Check files and database and include its report when requesting support.", missing.join(", "))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@ pub struct Outcome {
|
||||
}
|
||||
|
||||
fn step(report: &dyn Fn(&str, u8), name: &str, pct: u8) {
|
||||
tracing::info!(step = name, percent = pct, "server update progress");
|
||||
report(name, pct);
|
||||
}
|
||||
|
||||
@@ -259,6 +260,7 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
|
||||
|
||||
step(report, "Checking the update", 2);
|
||||
let (m, _) = fetch_manifest(&p.source, p.trusted_key)?;
|
||||
tracing::info!(root = %root.display(), from_version = ?meta.core.version, to_version = %m.version, migrations = m.migrations.len(), "server update selected");
|
||||
check_manifest(&m)?;
|
||||
let archive = m.archive.clone().ok_or_else(|| Error::InvalidManifest("no archive".into()))?;
|
||||
let id = format!("{}-{}-{}", chrono::Utc::now().format("%Y%m%d-%H%M%S"), m.version.replace('.', "_"), uuid::Uuid::new_v4().simple());
|
||||
@@ -384,7 +386,9 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result<Outcome> {
|
||||
}
|
||||
|
||||
fn fail_after_apply(p: &Params, txn: &mut Txn, before: &Path, tree: &Path, why: String, report: Option<ApplyReport>) -> Result<Outcome> {
|
||||
tracing::error!(transaction = %txn.id, databases_started = txn.databases_started, "server update failed; restoring recovery point");
|
||||
let restored = restore_transaction(p.root, p.meta_dir, before, txn, p.env);
|
||||
tracing::info!(transaction = %txn.id, recovered = restored.is_ok(), "server update recovery finished");
|
||||
txn.state = if restored.is_ok() { State::RolledBack } else { State::Failed };
|
||||
txn.message = Some(match &restored { Ok(()) => why.clone(), Err(e) => format!("{why} Recovery failed: {e}") });
|
||||
save(p.meta_dir, txn)?;
|
||||
|
||||
Reference in new issue
Block a user