Browse Source

add migrations

merge-requests/95/head
hamidreza kalbasi 5 years ago
parent
commit
9b11ec3dab
  1. 28
      src/database.rs

28
src/database.rs

@ -18,11 +18,7 @@ use log::{error, info}; @@ -18,11 +18,7 @@ use log::{error, info};
use rocket::futures::{self, channel::mpsc};
use ruma::{DeviceId, ServerName, UserId};
use serde::Deserialize;
use std::{
collections::HashMap,
fs::remove_dir_all,
sync::{Arc, RwLock},
};
use std::{collections::HashMap, fs::{self, remove_dir_all}, io::Write, sync::{Arc, RwLock}};
use tokio::sync::Semaphore;
#[derive(Clone, Debug, Deserialize)]
@ -253,9 +249,11 @@ impl Database { @@ -253,9 +249,11 @@ impl Database {
let password = utils::string_from_bytes(&password);
if password.map_or(false, |password| {
let password_not_exists = password.map_or(false, |password| {
argon2::verify_encoded(&password, b"").unwrap_or(false)
}) {
});
if password_not_exists {
db.users.userid_password.insert(userid, b"")?;
}
}
@ -265,6 +263,22 @@ impl Database { @@ -265,6 +263,22 @@ impl Database {
info!("Migration: 1 -> 2 finished");
}
if db.globals.database_version()? < 3 {
// Move media to filesystem
for r in db.media.mediaid_file.iter() {
let (key, content) = r?;
let path = db.globals.get_media_file(&key);
let mut file = fs::File::create(path)?;
file.write_all(&content)?;
db.media.mediaid_file.remove(&key)?;
db.media.mediaid_file.insert(&key, vec![])?;
}
db.globals.bump_database_version(3)?;
info!("Migration: 2 -> 3 finished");
}
// This data is probably outdated
db.rooms.edus.presenceid_presence.clear()?;

Loading…
Cancel
Save