Lines
100 %
Functions
Branches
//! A tenant left on an older schema is brought forward.
//!
//! The case the migrator exists for. A tenant created before a release carries
//! that release's migrations and nothing since; nothing else in the system ever
//! revisits it.
#![cfg(feature = "db")]
use server::fleet::migrate_fleet;
use tests_integration::fleet_support::{
accounted_for, admin_connect, admin_id, applied_migrations, create_database, enter_directory,
expected_migrations, is_fully_migrated, migrate_to_first, new_tenant, quarantine_of,
};
#[tokio::test]
async fn a_tenant_on_an_older_schema_is_brought_forward() -> anyhow::Result<()> {
let admin = admin_connect().await;
let (id, database_name, _id_guard) = new_tenant();
create_database(&admin, &database_name).await;
// Three of the five: an older release's worth of schema, not an empty one.
// Listed only afterwards, or a concurrent suite's fleet run can migrate it
// fully first and the partial run fails with VersionMissing.
migrate_to_first(&database_name, 3).await;
let before = applied_migrations(&database_name).await;
assert_eq!(before, 3, "precondition: the tenant starts partly migrated");
assert!(before < expected_migrations());
enter_directory(&admin, "fleet-old", id, &database_name).await;
let report = migrate_fleet(admin_id()).await?;
assert!(accounted_for(&report, id), "{report:?}");
assert!(
is_fully_migrated(&database_name).await,
"the remaining migrations must be applied, not skipped as 'already migrated'"
);
assert_eq!(quarantine_of(&admin, id).await, None);
Ok(())
}