Fix database version check & code formating

merge-requests/413/merge
Paul Beziau 2 years ago
parent 9c0c74f547
commit d47c1a8ba6

@ -7,7 +7,8 @@ use directories::ProjectDirs;
use lru_cache::LruCache; use lru_cache::LruCache;
use ruma::{ use ruma::{
events::{ events::{
push_rules::{PushRulesEventContent, PushRulesEvent}, room::message::RoomMessageEventContent, push_rules::{PushRulesEvent, PushRulesEventContent},
room::message::RoomMessageEventContent,
GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType, GlobalAccountDataEvent, GlobalAccountDataEventType, StateEventType,
}, },
push::Ruleset, push::Ruleset,
@ -405,7 +406,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 = 11; let latest_database_version = 12;
if services().users.count()? > 0 { if services().users.count()? > 0 {
// MIGRATIONS // MIGRATIONS
@ -802,22 +803,23 @@ impl KeyValueDatabase {
} }
if services().globals.database_version()? < 12 { if services().globals.database_version()? < 12 {
for username in services().users.list_local_users().unwrap() { for username in services().users.list_local_users().unwrap() {
let user =
let user = UserId::parse_with_server_name(username, services().globals.server_name()) UserId::parse_with_server_name(username, services().globals.server_name())
.unwrap(); .unwrap();
let raw_rules_list = services()
let raw_rules_list = services().account_data .account_data
.get( .get(
None, None,
&user, &user,
GlobalAccountDataEventType::PushRules.to_string().into()) GlobalAccountDataEventType::PushRules.to_string().into(),
)
.unwrap() .unwrap()
.expect("Username is invalid"); .expect("Username is invalid");
let mut account_data = serde_json::from_str::<PushRulesEvent>(raw_rules_list.get()).unwrap(); let mut account_data =
serde_json::from_str::<PushRulesEvent>(raw_rules_list.get()).unwrap();
let rules_list = &mut account_data.content.global; let rules_list = &mut account_data.content.global;
//content rule //content rule
@ -836,12 +838,16 @@ impl KeyValueDatabase {
//underride rules //underride rules
{ {
let underride_rule_transformation = let underride_rule_transformation = [
[[".m.rules.call", ".m.rule.call"], [".m.rules.call", ".m.rule.call"],
[".m.rules.room_one_to_one", ".m.rule.room_one_to_one"], [".m.rules.room_one_to_one", ".m.rule.room_one_to_one"],
[".m.rules.encrypted_room_one_to_one", ".m.rule.encrypted_room_one_to_one"], [
".m.rules.encrypted_room_one_to_one",
".m.rule.encrypted_room_one_to_one",
],
[".m.rules.message", ".m.rule.message"], [".m.rules.message", ".m.rule.message"],
[".m.rules.encrypted", ".m.rule.encrypted"]]; [".m.rules.encrypted", ".m.rule.encrypted"],
];
for transformation in underride_rule_transformation { for transformation in underride_rule_transformation {
let rule = rules_list.underride.get(transformation[0]); let rule = rules_list.underride.get(transformation[0]);
@ -867,7 +873,10 @@ impl KeyValueDatabase {
warn!("Migration: 11 -> 12 finished"); warn!("Migration: 11 -> 12 finished");
} }
assert_eq!(11, latest_database_version); assert_eq!(
services().globals.database_version().unwrap(),
latest_database_version
);
info!( info!(
"Loaded {} database with version {}", "Loaded {} database with version {}",

Loading…
Cancel
Save