Skip to main content

headless_lms_server/controllers/mock_suotar/
default_world.rs

1//! The world installed when nothing has been pushed, and the marker that says which database it
2//! belongs to.
3//!
4//! Built from the same fixtures the seed writes its database rows from: the restore-from-template
5//! setup path runs no seed, and a world of the mock's own there would hand the two setup paths
6//! different fixtures.
7
8use sqlx::PgPool;
9
10use crate::prelude::*;
11
12use super::commands::world_from_push;
13use super::fixtures::{SUOTAR_COURSE_ID, mock_suotar_world};
14use super::store::World;
15
16pub fn build() -> World {
17    world_from_push(mock_suotar_world())
18}
19
20/// Something the database also knows, so a world installed against a *different* database shows up as
21/// a diagnostic. Staleness inside one restored template is invisible to it, which is what the flush on
22/// that path is for. The mock's only read of Postgres, and it never writes.
23pub async fn db_generation_marker(pool: &PgPool) -> Option<String> {
24    let mut conn = pool.acquire().await.ok()?;
25    let course = models::courses::get_course(&mut conn, SUOTAR_COURSE_ID)
26        .await
27        .ok()?;
28    Some(format!("db{}", course.created_at.timestamp_millis()))
29}