diff --git a/changelog.d/20261016-consistent-update-migrations.md b/changelog.d/20261016-consistent-update-migrations.md index bddc9da..2f9e794 100644 --- a/changelog.d/20261016-consistent-update-migrations.md +++ b/changelog.d/20261016-consistent-update-migrations.md @@ -1,7 +1,7 @@ --- area: manager -type: fixed +type: changed audience: admins -title: Rehearsal and installation use the same database migration checks +title: Server updates apply migrations once after saving a recovery point --- -Both phases use one migration executor and check both realms before changing either. Duplicate migration entries are rejected before SQL runs. +Updates no longer build and start a second full server copy. The Manager checks both realms, saves recovery, applies pending SQL once and verifies startup. Failed SQL or startup restores the recovery point. Full-copy upgrade testing remains a release task. diff --git a/crates/coa-core/src/mysql_snapshot.rs b/crates/coa-core/src/mysql_snapshot.rs index 9a91cf8..078d8f1 100644 --- a/crates/coa-core/src/mysql_snapshot.rs +++ b/crates/coa-core/src/mysql_snapshot.rs @@ -129,10 +129,6 @@ pub(crate) fn inventory(root: &Path) -> Result> { } pub(crate) fn copy_verified(source: &Path, target: &Path, files: &BTreeMap) -> Result<()> { - copy_verified_with_progress(source, target, files, &|_| {}) -} - -fn copy_verified_with_progress(source: &Path, target: &Path, files: &BTreeMap, report: &dyn Fn(&str)) -> Result<()> { if target.exists() { return Err(Error::Invalid("Database snapshot destination already exists.".into())); } let bytes = files.keys().try_fold(0u64, |total, name| -> Result { let path = fsx::ensure_within(source, &fsx::safe_join(source, name)?)?; @@ -142,15 +138,13 @@ fn copy_verified_with_progress(source: &Path, target: &Path, files: &BTreeMap Result<()> { Ok(()) } -pub(crate) fn rehearsal_copy_with_progress(root: &Path, meta: &Path, point: &Path, snapshot: &Snapshot, report: &dyn Fn(&str)) -> Result { - report("Verifying the database recovery copy before rehearsal"); - verify(point, snapshot)?; - let canonical = fsx::canonicalize_lenient(root)?; - let root = canonical.as_path(); - let destination = meta.join("rehearsals").join(uuid::Uuid::new_v4().simple().to_string()).join("server"); - let mut files = BTreeMap::new(); - let mut file_bytes = 0u64; - let mut directories = vec![root.to_path_buf()]; - while let Some(directory) = directories.pop() { - for entry in fs::read_dir(directory)? { - let entry = entry?; - let raw = entry.path(); - let relative = raw.strip_prefix(root).map_err(|e| Error::Invalid(e.to_string()))?.to_string_lossy().replace('\\', "/"); - let lower = relative.to_ascii_lowercase(); - let first = lower.split('/').next().unwrap(); - if entry.file_type()?.is_dir() && !relative.contains('/') - && !["core", "data", "scripts", "settings", "runtime", "mysql", ".realms", "bugreport", "extras", "licenses"].contains(&first) { continue; } - if lower == "mysql/data" || lower.starts_with("mysql/data-") - || lower.split('/').any(|part| part == ".state") - || lower == "bugreport/reports" || lower == "core/logs" || lower == "mysql/logs" { continue; } - let metadata = fs::symlink_metadata(&raw)?; - reject_link(&metadata)?; - let path = fsx::ensure_within(root, &raw)?; - if metadata.is_dir() { directories.push(path); } - else if metadata.is_file() { - file_bytes = file_bytes.checked_add(metadata.len()).ok_or_else(|| Error::Invalid("Private copy size overflow.".into()))?; - files.insert(relative, fsx::sha256_file(&path)?); - if files.len() % 250 == 0 { report(&format!("Preparing the private copy: {} files checked", files.len())); } - } - else { return Err(Error::Invalid("Unsupported rehearsal file.".into())); } - } - } - let needed = file_bytes.checked_add(snapshot.expanded_bytes.max(snapshot.bytes)).ok_or_else(|| Error::Invalid("Private copy size overflow.".into()))?; - fsx::require_space(meta, needed)?; - copy_verified_with_progress(root, &destination, &files, report)?; - report("Restoring MySQL into the private server copy"); - copy_snapshot(point, snapshot, &destination.join("mysql/data"))?; - let (_, mut installed) = crate::registry::MetaDir::open(meta)?; - installed.id = uuid::Uuid::new_v4().to_string(); - installed.server_path = destination.to_string_lossy().into_owned(); - installed.client_path = None; - crate::registry::MetaDir::create(&destination, &installed)?; - Ok(destination) -} - -pub(crate) fn isolate_connections(root: &Path) -> Result<()> { - for relative in ["Settings/worldserver.conf.template", "Settings/authserver.conf.template", "Core/configs/worldserver.conf", "Core/configs/authserver.conf"] { - let path = fsx::ensure_within(root, &root.join(relative))?; - if !path.is_file() { - if relative.ends_with(".template") { return Err(Error::Invalid("The private update copy lacks connection templates.".into())); } - continue; - } - let mut config = crate::config::parser::ConfFile::parse_bytes(&fs::read(&path)?)?; - for key in ["LoginDatabaseInfo", "WorldDatabaseInfo", "CharacterDatabaseInfo"] { - if relative.contains("worldserver") || key == "LoginDatabaseInfo" { - config.set(key, &format!("\"@{key}@\""), &[]); - } - } - config.set("BindIP", "\"127.0.0.1\"", &[]); - if relative.contains("worldserver") { - config.set("Ra.IP", "\"127.0.0.1\"", &[]); - config.set("DataDir", "\"@DATA@\"", &[]); - } - fsx::atomic_write(&path, config.to_text().as_bytes())?; - } - Ok(()) -} - -pub(crate) fn unchanged(root: &Path, snapshot: &Snapshot) -> Result<()> { - let data = fsx::ensure_within(root, &root.join("mysql/data"))?; - if inventory(&data)? != snapshot.files || directories(&data)? != snapshot.directories { - return Err(Error::Invalid("The installed database changed during the private rehearsal. Retry after stopping other database access.".into())); - } - Ok(()) -} - -pub(crate) fn validate_connections(templates: &Path, installation: &Path) -> Result<()> { - let port = crate::layout::read_ports(installation).mysql.to_string(); - let (_, password) = crate::db::credentials(installation)?; - let realm = crate::realms::state(installation)?.active; - for relative in ["Settings/worldserver.conf.template", "Settings/authserver.conf.template"] { - let path = fsx::ensure_within(templates, &templates.join(relative))?; - let config = crate::config::parser::ConfFile::parse_bytes(&fs::read(path)?)?; - for (key, kind) in [("LoginDatabaseInfo", "auth"), ("WorldDatabaseInfo", "world"), ("CharacterDatabaseInfo", "characters")] { - if relative.contains("authserver") && kind != "auth" { continue; } - let value = config.get(key).ok_or_else(|| Error::Invalid(format!("The update cannot isolate the missing {key} connection.")))?.trim().trim_matches('"'); - if value == format!("@{key}@") { continue; } - let fields: Vec<_> = value.split(';').collect(); - if fields.len() != 5 || !matches!(fields[0], "127.0.0.1" | "localhost") || fields[1] != port || fields[2] != "acore" || fields[3] != password || fields[4] != realm.schema(kind)? { - return Err(Error::Invalid(format!("The {key} connection does not use this repack's bundled database. A private update cannot safely qualify an external database."))); - } - } - } - Ok(()) -} - // Keep the replaced data directory. If interrupted between renames, a retry can install a new verified copy. pub(crate) fn swap(root: &Path, meta: &Path, point: &Path, snapshot: &Snapshot, fail_after_move: bool) -> Result { verify(point, snapshot)?; @@ -664,57 +561,10 @@ mod tests { fsx::atomic_write(&archive_path, b"damaged").unwrap(); assert!(verify(&point, &snapshot).is_err()); } - #[test] - fn private_rehearsals_reject_external_database_connections() { - let (_temp, root, _meta, _point, _snapshot) = fixture(); - fsx::atomic_write_json(&root.join("Settings/repack.json"), &serde_json::json!({"mysqlPort":3307})).unwrap(); - fsx::atomic_write_json(&root.join("Settings/database.json"), &serde_json::json!({"rootPassword":"test-root","appPassword":"test-app"})).unwrap(); - fsx::atomic_write(&root.join("Settings/worldserver.conf.template"), b"LoginDatabaseInfo = \"@LoginDatabaseInfo@\"\nWorldDatabaseInfo = \"@WorldDatabaseInfo@\"\nCharacterDatabaseInfo = \"@CharacterDatabaseInfo@\"\n").unwrap(); - fsx::atomic_write(&root.join("Settings/authserver.conf.template"), b"LoginDatabaseInfo = \"127.0.0.1;3307;acore;test-app;acore_auth\"\n").unwrap(); - validate_connections(&root, &root).unwrap(); - fsx::atomic_write(&root.join("Settings/authserver.conf.template"), b"LoginDatabaseInfo = \"192.0.2.1;3307;acore;test-app;acore_auth\"\n").unwrap(); - let error = validate_connections(&root, &root).unwrap_err().to_string(); - assert!(error.contains("external database")); - assert!(!error.contains("test-app")); - } - #[test] - fn a_changed_live_database_invalidates_the_rehearsal() { - let (_temp, root, _meta, _point, snapshot) = fixture(); - assert!(unchanged(&root, &snapshot).is_err()); - fsx::atomic_write(&root.join("mysql/data/characters.ibd"), b"saved").unwrap(); - fs::create_dir_all(root.join("mysql/data/empty_schema")).unwrap(); - unchanged(&root, &snapshot).unwrap(); - fsx::atomic_write(&root.join("mysql/data/extra.ibd"), b"new data").unwrap(); - assert!(unchanged(&root, &snapshot).is_err()); - } - #[test] - fn rehearsal_copy_succeeds_with_nested_directories_and_unnormalized_root() { - let (_temp, root, meta, point, snapshot) = fixture(); - let meta_obj = crate::registry::InstallMeta::new(crate::registry::InstallKind::New, &root); - fsx::atomic_write_json(&meta.join("install.json"), &meta_obj).unwrap(); - fsx::atomic_write(&root.join("Core/worldserver.exe"), b"exe").unwrap(); - fsx::atomic_write(&root.join("Core/configs/worldserver.conf"), b"conf").unwrap(); - fsx::atomic_write(&root.join("Settings/repack.json"), b"{}").unwrap(); - let phases = std::cell::RefCell::new(Vec::new()); - let dest = rehearsal_copy_with_progress(&root, &meta, &point, &snapshot, &|phase| phases.borrow_mut().push(phase.to_string())).unwrap(); - assert_eq!(fs::read(dest.join("Core/configs/worldserver.conf")).unwrap(), b"conf"); - assert_eq!(fs::read(dest.join("mysql/data/characters.ibd")).unwrap(), b"saved"); - let phases = phases.into_inner(); - assert!(phases[0].contains("Verifying the database")); - assert!(phases.iter().any(|phase| phase.contains("Copying private server files"))); - assert!(phases.last().unwrap().contains("Restoring MySQL")); - } - #[test] - fn rehearsal_checks_combined_program_and_database_space_before_copying() { - let (_temp, root, meta, point, mut snapshot) = fixture(); - fs::create_dir_all(&meta).unwrap(); - fsx::atomic_write(&root.join("Core/worldserver.exe"), b"exe").unwrap(); - snapshot.expanded_bytes = fsx::free_space(&meta).unwrap().saturating_add(1024 * 1024 * 1024); - let error = rehearsal_copy_with_progress(&root, &meta, &point, &snapshot, &|_| {}).unwrap_err(); - assert!(matches!(error, Error::InsufficientSpace { .. })); - assert!(!meta.join("rehearsals").exists()); - assert_eq!(fs::read(root.join("mysql/data/characters.ibd")).unwrap(), b"live"); - } + + + + } diff --git a/crates/coa-core/src/release_schema.rs b/crates/coa-core/src/release_schema.rs index bb6a44e..1022215 100644 --- a/crates/coa-core/src/release_schema.rs +++ b/crates/coa-core/src/release_schema.rs @@ -14,8 +14,6 @@ impl crate::update::Env for QualificationEnv<'_> { fn preflight(&self, manifest: &crate::manifest::Manifest) -> Result<()> { self.0.preflight(manifest) } fn snapshot(&self) -> Result { self.0.snapshot() } fn verify_snapshot(&self, id: &str) -> Result<()> { self.0.verify_snapshot(id) } - fn rehearse(&self, manifest: &crate::manifest::Manifest, tree: &Path, items: &[crate::update::PlanItem], point: &str) -> Result<()> { self.0.rehearse(manifest, tree, items, point) } - fn rehearse_with_progress(&self, manifest: &crate::manifest::Manifest, tree: &Path, items: &[crate::update::PlanItem], point: &str, report: &dyn Fn(&str, u8)) -> Result<()> { self.0.rehearse_with_progress(manifest, tree, items, point, report) } fn restore_snapshot(&self, id: &str) -> Result<()> { self.0.restore_snapshot(id) } fn migrate(&self, manifest: &crate::manifest::Manifest, staged: &Path) -> Result { self.0.migrate(manifest, staged) } fn validate(&self) -> Result<()> { self.0.validate() } @@ -87,7 +85,7 @@ pub fn qualify_upgrade(base: &Path, source: &Path, candidate: &Path, fixture: &P "schema": 1, "result": "passed", "fromVersion": source_manifest.version, "toVersion": candidate_manifest.version, "fromManifestSha256": fsx::sha256_bytes(&source_bytes), "fromSchemaSha256": source_manifest.files.iter().find(|file| file.path == schema_check::CONTRACT).map(|file| &file.sha256), - "checks": ["manager-transaction", "private-user-database-rehearsal", "database-schema", "private-auth-world-startup", "existing-identities", "user-file-preservation"], + "checks": ["manager-transaction", "recovery-backed-database-update", "database-schema", "private-auth-world-startup", "existing-identities", "user-file-preservation"], })) } diff --git a/crates/coa-core/src/update.rs b/crates/coa-core/src/update.rs index 8bd041e..5537e17 100644 --- a/crates/coa-core/src/update.rs +++ b/crates/coa-core/src/update.rs @@ -92,9 +92,6 @@ pub trait Env { fn ensure_stopped(&self) -> Result<()>; fn preflight(&self, _manifest: &Manifest) -> Result<()> { Ok(()) } fn verify_snapshot(&self, _id: &str) -> Result<()> { Ok(()) } - fn rehearse(&self, _manifest: &Manifest, _tree: &Path, _items: &[PlanItem], _point: &str) -> Result<()> { Ok(()) } - fn rehearse_with_progress(&self, manifest: &Manifest, tree: &Path, items: &[PlanItem], point: &str, _report: &dyn Fn(&str, u8)) -> Result<()> { self.rehearse(manifest, tree, items, point) } - /// Create a recovery point for the databases and configuration; returns its id. fn snapshot(&self) -> Result; fn restore_snapshot(&self, id: &str) -> Result<()>; fn migrate(&self, manifest: &Manifest, staged_migrations: &Path) -> Result; @@ -512,14 +509,6 @@ pub fn apply(p: &Params, report: &dyn Fn(&str, u8)) -> Result { let point_meta = crate::backup::point_json(meta_dir, txn.recovery_point.as_deref().unwrap())?; if point_meta.is_file() { txn.recovery_hashes.insert("@point".into(), fsx::sha256_file(&point_meta)?); } save(meta_dir, &txn)?; - step(report, "Testing the update on a private copy of your server", 54); - if let Err(error) = p.env.rehearse_with_progress(&m, &tree, &items, txn.recovery_point.as_deref().unwrap(), report) { - txn.state = State::Failed; - txn.message = Some(format!("The private update rehearsal failed: {error}. The installed server was not updated.")); - save(meta_dir, &txn)?; - return Err(Error::Invalid(txn.message.unwrap())); - } - txn.ops = items .iter() .filter(|i| i.action != Action::Skip) @@ -973,78 +962,6 @@ impl Env for RepackEnv<'_> { } fn automatic_rollback(&self) -> bool { true } - fn rehearse(&self, manifest: &Manifest, tree: &Path, items: &[PlanItem], id: &str) -> Result<()> { - self.rehearse_with_progress(manifest, tree, items, id, &|_, _| {}) - } - - fn rehearse_with_progress(&self, manifest: &Manifest, tree: &Path, items: &[PlanItem], id: &str, report: &dyn Fn(&str, u8)) -> Result<()> { - if items.iter().any(|item| item.action != Action::Skip && item.path.to_ascii_lowercase().starts_with("mysql/")) { - return Err(Error::Invalid("A server update cannot replace MySQL while using a cold recovery copy; a separate database engine upgrade is required.".into())); - } - let point = crate::backup::get(self.meta_dir, id)?; - let Some(snapshot) = &point.mysql_snapshot else { - // Docker uses its separate experimental release channel until its clone runner is qualified. - if crate::docker::is_docker(self.root) { return Ok(()); } - return Err(Error::Invalid("This installation has no complete MySQL recovery copy for an update rehearsal.".into())); - }; - crate::mysql_snapshot::validate_connections(self.root, self.root)?; - crate::mysql_snapshot::stop(self.root)?; - let point_dir = crate::backup::point_json(self.meta_dir, id)?.parent().unwrap().to_path_buf(); - let fixture = crate::mysql_snapshot::rehearsal_copy_with_progress(self.root, self.meta_dir, &point_dir, snapshot, &|phase| step(report, phase, 54))?; - let metadata = crate::registry::metadata_dir_for(&fixture)?; - let env = RepackEnv { root: &fixture, meta_dir: &metadata }; - let result = crate::install::with_scratch_ports(&fixture, || { - let mut txn = Txn { id: "rehearsal".into(), state: State::Applying, from_version: None, - to_version: manifest.version.clone(), recovery_point: None, databases_started: false, - ops: items.iter().filter(|item| item.action != Action::Skip).map(|item| Op { - path: item.path.clone(), action: item.action, reason: item.reason.clone(), - new_sha256: manifest.files.iter().find(|file| file.path == item.path).unwrap().sha256.clone(), - had_previous: fsx::safe_join(&fixture, &item.path).is_ok_and(|path| path.is_file()), started:false, done:false, - }).collect(), message:None, recovery_hashes:BTreeMap::new() }; - let before = txn_dir(&metadata, &txn.id)?.join("before"); - fs::create_dir_all(&before)?; - step(report, "Applying update files to the private server copy", 55); - apply_ops(&fixture, tree, &before, &manifest.files, &mut txn, &metadata, None)?; - crate::mysql_snapshot::validate_connections(&fixture, self.root)?; - crate::mysql_snapshot::isolate_connections(&fixture)?; - step(report, "Testing database updates on the private server copy", 56); - let identities = crate::backup::with_database(&fixture, |db| { - let identities = database_identities(db)?; - let result = migrate_databases(db, &fixture, manifest, &tree.join("_migrations"), &|| Ok("private rehearsal".into()))?; - if let Some((migration, error)) = result.failed { - return Err(Error::Invalid(format!("Rehearsal migration {migration} failed: {error}"))); - } - verify_database_identities(db, &identities)?; - Ok(identities) - })?; - step(report, "Testing startup of the private server copy", 57); - env.validate()?; - crate::backup::with_database(&fixture, |db| verify_database_identities(db, &identities))?; - env.ensure_stopped() - }); - step(report, "Stopping the private server copy and verifying the installed database", 57); - let stopped = crate::mysql_snapshot::stop(&fixture); - let live_state = if result.is_ok() { crate::mysql_snapshot::stop(self.root).and_then(|()| crate::mysql_snapshot::unchanged(self.root, snapshot)) } else { Ok(()) }; - let logs: BTreeMap<_, _> = ["Core/Logs/auth-console.log", "Core/Logs/world-console.log", "Core/Logs/supervisor.log", "mysql/logs/mysql-error.log"].into_iter() - .map(|path| (path, crate::diag::redact(&crate::health::tail(&fixture.join(path), 32768)))).collect(); - let mut schema_reports = Vec::::new(); - if let Ok(entries) = fs::read_dir(metadata.join("diagnostics")) { - for entry in entries.flatten().filter(|entry| entry.file_name().to_string_lossy().starts_with("schema-validation-")) { - let path = fsx::ensure_within(&metadata, &entry.path())?; - if fs::metadata(&path)?.len() <= 4 * 1024 * 1024 { schema_reports.push(fsx::read_json(&path)?); } - } - } - let report = serde_json::json!({"schema":1,"checkedAt":chrono::Utc::now().to_rfc3339(),"toVersion":manifest.version,"recoveryPoint":id, - "result":if result.is_ok() && stopped.is_ok() && live_state.is_ok() {"passed"} else {"failed"}, "error":result.as_ref().err().map(ToString::to_string), "stopError":stopped.as_ref().err().map(ToString::to_string), "liveStateError":live_state.as_ref().err().map(ToString::to_string), "logs":logs,"schemaReports":schema_reports,"fixture":fixture}); - let report_path = self.meta_dir.join("diagnostics").join(format!("database-rehearsal-{}.json", uuid::Uuid::new_v4())); - fsx::atomic_write_json(&report_path, &report)?; - stopped?; - let parent = fixture.parent().unwrap(); - let owned = fsx::ensure_within(&self.meta_dir.join("rehearsals"), parent)?; - fs::remove_dir_all(owned)?; - live_state?; - result - } fn preflight(&self, manifest: &Manifest) -> Result<()> { crate::mysql_snapshot::stop_previous_rehearsals(self.meta_dir)?; if let Some(compatibility) = &manifest.compatibility { @@ -1064,7 +981,7 @@ impl Env for RepackEnv<'_> { if crate::docker::is_docker(self.root) { return Err(Error::Invalid(format!("The installed {} database does not match its upgrade source: {}.{}: {}", mode.name(), problem.database, problem.table, problem.detail))); } - tracing::warn!(realm = mode.name(), table = %problem.table, "Installed schema differs; the private candidate rehearsal must qualify this database"); + tracing::warn!(realm = mode.name(), table = %problem.table, "Installed schema differs; pending migrations and target validation will run with a full recovery point"); } } Ok(()) @@ -1120,7 +1037,10 @@ impl Env for RepackEnv<'_> { fn migrate(&self, manifest: &Manifest, staged: &Path) -> Result { crate::backup::with_database(self.root, |db| { - migrate_databases(db, self.root, manifest, staged, &|| self.migration_snapshot()) + let identities = database_identities(db)?; + let result = migrate_databases(db, self.root, manifest, staged, &|| self.migration_snapshot())?; + if result.failed.is_none() { verify_database_identities(db, &identities)?; } + Ok(result) }) } @@ -1203,7 +1123,7 @@ impl RepackEnv<'_> { } -/// Rehearsal and installation use the same database order, history checks and SQL executor. +/// One migration pass for both realms, with shared history checks and one recovery point. fn migrate_databases(db: &crate::db::Db, root: &Path, manifest: &Manifest, staged: &Path, snapshot: &dyn Fn() -> Result) -> Result { let realms = crate::realms::state(root)?; let mut modes = vec![realms.active]; @@ -1284,19 +1204,15 @@ mod tests { migrate_fail: Cell, preflight_fail: Cell, restore_fail: Cell, - rehearsal_fail: Cell, } impl Fake { fn ok() -> Fake { - Fake { activation_expected: RefCell::new(None), activation_failed: Cell::new(false), activated: Cell::new(false), automatic_rollback: Cell::new(false), recovery_healthy: Cell::new(true), stopped: Cell::new(true), healthy: Cell::new(true), snapshot_ok: Cell::new(true), calls: Default::default(), migrate_fail: Cell::new(false), preflight_fail: Cell::new(false), restore_fail: Cell::new(false), rehearsal_fail: Cell::new(false) } + Fake { activation_expected: RefCell::new(None), activation_failed: Cell::new(false), activated: Cell::new(false), automatic_rollback: Cell::new(false), recovery_healthy: Cell::new(true), stopped: Cell::new(true), healthy: Cell::new(true), snapshot_ok: Cell::new(true), calls: Default::default(), migrate_fail: Cell::new(false), preflight_fail: Cell::new(false), restore_fail: Cell::new(false) } } } impl Env for Fake { - fn rehearse(&self, _: &Manifest, _: &Path, _: &[PlanItem], _: &str) -> Result<()> { - if self.rehearsal_fail.get() { Err(Error::Invalid("SQL failed in the private copy".into())) } else { Ok(()) } - } fn activate(&self) -> Result<()> { if let Some((meta, version)) = self.activation_expected.borrow().as_ref() { ensure_recovered(meta)?; @@ -2045,20 +1961,17 @@ mod tests { } #[test] - fn failed_rehearsal_preserves_installed_files_version_and_recovery_point() { + fn update_saves_recovery_then_migrates_and_validates_once() { let w = world(&[], true); let env = Fake::ok(); - env.rehearsal_fail.set(true); - let original = fsx::sha256_file(&w.meta.join("install.json")).unwrap(); - let error = run(&w, &env, BTreeMap::new(), None).unwrap_err(); - assert!(error.to_string().contains("installed server was not updated")); - assert_eq!(read(&w, "Core/worldserver.exe"), b"world-v1"); - assert_eq!(fsx::sha256_file(&w.meta.join("install.json")).unwrap(), original); - assert_eq!(&*env.calls.borrow(), &["stop", "snapshot"]); - assert!(pending_checked(&w.meta).unwrap().is_none()); - let journal = journals(&w.meta).unwrap().remove(0); - assert_eq!(journal.recovery_point.as_deref(), Some("rp-1")); - assert!(!journal.databases_started && journal.ops.is_empty()); + let result = run(&w, &env, BTreeMap::new(), None).unwrap(); + assert_eq!(result.txn.state, State::Committed); + let calls = env.calls.borrow(); + assert_eq!(calls.iter().filter(|call| **call == "snapshot").count(), 1); + assert_eq!(calls.iter().filter(|call| **call == "migrate").count(), 1); + assert_eq!(calls.iter().filter(|call| **call == "validate").count(), 1); + assert!(calls.iter().position(|call| *call == "snapshot") < calls.iter().position(|call| *call == "migrate")); + assert!(!w.meta.join("rehearsals").exists()); } #[test] diff --git a/docs/UPDATE-WORKFLOW.md b/docs/UPDATE-WORKFLOW.md index 9a57352..4ca8127 100644 --- a/docs/UPDATE-WORKFLOW.md +++ b/docs/UPDATE-WORKFLOW.md @@ -2,9 +2,11 @@ Version compatibility selects a package; it does not prove that a particular installed database can apply it. -The updater verifies the signed manifest and archive, checks file changes, stops the server, and saves one complete recovery point. Rehearsal and installation call the same database migration executor. That executor checks both realms before changing either, applies shared authentication migrations once, and uses the same pending-SQL selection as the preview count. Applied migrations are skipped; changed checksums and interrupted/failed records stop the update. Duplicate SQL identifiers for the same schema are rejected before execution. +The updater verifies the signed manifest and archive, checks file changes and database history, stops the server, and saves one complete recovery point. It then replaces files, applies pending SQL once, verifies the target schema and starts the updated server once for validation. Shared authentication migrations run once; both realm histories are checked before changing either. Account and character identities are compared before and after migration. -The existing recovery journal, configuration merge, private-copy checks and startup verification remain enabled. This change does not relax the package compatibility matrix, force a migration through its SQL guards, or mark unexecuted SQL as applied. +Applied migrations are skipped; changed checksums and interrupted/failed records stop the update. Duplicate SQL identifiers for the same schema are rejected before execution. SQL or startup failure restores files and databases together. If recovery fails, startup remains blocked and the recovery artifacts remain available. + +The per-update nested server rehearsal has been removed. Full-copy upgrade/startup testing belongs to release qualification, on independent disposable installations. Cleanup of interrupted rehearsals from older Manager versions remains for compatibility. Signed packages, recovery verification, configuration merge and startup validation stay enabled. No migration guard is bypassed, no unexecuted SQL is marked applied, and the package compatibility matrix is unchanged. ## Verify with an actual installation copy