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, expected_migrations, forget_tenant,
is_fully_migrated, migrate_to_first, quarantine_of, register_tenant,
};
#[tokio::test]
async fn a_tenant_on_an_older_schema_is_brought_forward() -> anyhow::Result<()> {
let admin = admin_connect().await;
let (id, database_name) = register_tenant(&admin, "fleet-old", true).await;
// Three of the five: an older release's worth of schema, not an empty one.
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());
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);
forget_tenant(&admin, id, &database_name).await;
Ok(())
}