1
//! A tenant left on an older schema is brought forward.
2
//!
3
//! The case the migrator exists for. A tenant created before a release carries
4
//! that release's migrations and nothing since; nothing else in the system ever
5
//! revisits it.
6
#![cfg(feature = "db")]
7

            
8
use server::fleet::migrate_fleet;
9
use tests_integration::fleet_support::{
10
    accounted_for, admin_connect, admin_id, applied_migrations, create_database, enter_directory,
11
    expected_migrations, is_fully_migrated, migrate_to_first, new_tenant, quarantine_of,
12
};
13

            
14
#[tokio::test]
15
1
async fn a_tenant_on_an_older_schema_is_brought_forward() -> anyhow::Result<()> {
16
1
    let admin = admin_connect().await;
17
1
    let (id, database_name, _id_guard) = new_tenant();
18
1
    create_database(&admin, &database_name).await;
19

            
20
    // Three of the five: an older release's worth of schema, not an empty one.
21
    // Listed only afterwards, or a concurrent suite's fleet run can migrate it
22
    // fully first and the partial run fails with VersionMissing.
23
1
    migrate_to_first(&database_name, 3).await;
24
1
    let before = applied_migrations(&database_name).await;
25
1
    assert_eq!(before, 3, "precondition: the tenant starts partly migrated");
26
1
    assert!(before < expected_migrations());
27
1
    enter_directory(&admin, "fleet-old", id, &database_name).await;
28

            
29
1
    let report = migrate_fleet(admin_id()).await?;
30

            
31
1
    assert!(accounted_for(&report, id), "{report:?}");
32
1
    assert!(
33
1
        is_fully_migrated(&database_name).await,
34
        "the remaining migrations must be applied, not skipped as 'already migrated'"
35
    );
36
1
    assert_eq!(quarantine_of(&admin, id).await, None);
37
2
    Ok(())
38
1
}