diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index f0849a1bc..a7bb6236c 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -1231,6 +1231,35 @@ impl Sql { .await .with_context(|| format!("execute_migration failed for version {version}"))?; - self.set_db_version_in_cache(version).await + self.config_cache.write().await.clear(); + + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::config::Config; + use crate::test_utils::TestContext; + + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_clear_config_cache() -> anyhow::Result<()> { + // Some migrations change the `config` table in SQL. + // This test checks that the config cache is invalidated in `execute_migration()`. + + let t = TestContext::new().await; + assert_eq!(t.get_config_bool(Config::IsChatmail).await?, false); + + t.sql + .execute_migration( + "INSERT INTO config (keyname, value) VALUES ('is_chatmail', '1')", + 1000, + ) + .await?; + assert_eq!(t.get_config_bool(Config::IsChatmail).await?, true); + assert_eq!(t.sql.get_raw_config_int(VERSION_CFG).await?.unwrap(), 1000); + + Ok(()) } }