mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-17 12:50:50 +01:00
Add a database migration to fix and update the default pushrules
This commit is contained in:
parent
88c6bf7595
commit
1929ca5d9d
1 changed files with 47 additions and 1 deletions
|
@ -411,7 +411,7 @@ impl KeyValueDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the database has any data, perform data migrations before starting
|
// If the database has any data, perform data migrations before starting
|
||||||
let latest_database_version = 12;
|
let latest_database_version = 13;
|
||||||
|
|
||||||
if services().users.count()? > 0 {
|
if services().users.count()? > 0 {
|
||||||
// MIGRATIONS
|
// MIGRATIONS
|
||||||
|
@ -880,6 +880,52 @@ impl KeyValueDatabase {
|
||||||
warn!("Migration: 11 -> 12 finished");
|
warn!("Migration: 11 -> 12 finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This migration can be reused as-is anytime the server-default rules are updated.
|
||||||
|
if services().globals.database_version()? < 13 {
|
||||||
|
for username in services().users.list_local_users()? {
|
||||||
|
let user = match UserId::parse_with_server_name(
|
||||||
|
username.clone(),
|
||||||
|
services().globals.server_name(),
|
||||||
|
) {
|
||||||
|
Ok(u) => u,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("Invalid username {username}: {e}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let raw_rules_list = services()
|
||||||
|
.account_data
|
||||||
|
.get(
|
||||||
|
None,
|
||||||
|
&user,
|
||||||
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.expect("Username is invalid");
|
||||||
|
|
||||||
|
let mut account_data =
|
||||||
|
serde_json::from_str::<PushRulesEvent>(raw_rules_list.get()).unwrap();
|
||||||
|
|
||||||
|
let user_default_rules = ruma::push::Ruleset::server_default(&user);
|
||||||
|
account_data
|
||||||
|
.content
|
||||||
|
.global
|
||||||
|
.update_with_server_default(user_default_rules);
|
||||||
|
|
||||||
|
services().account_data.update(
|
||||||
|
None,
|
||||||
|
&user,
|
||||||
|
GlobalAccountDataEventType::PushRules.to_string().into(),
|
||||||
|
&serde_json::to_value(account_data).expect("to json value always works"),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
services().globals.bump_database_version(13)?;
|
||||||
|
|
||||||
|
warn!("Migration: 12 -> 13 finished");
|
||||||
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
services().globals.database_version().unwrap(),
|
services().globals.database_version().unwrap(),
|
||||||
latest_database_version
|
latest_database_version
|
||||||
|
|
Loading…
Reference in a new issue