mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Patch dump v4
This commit is contained in:
parent
b9a79eb858
commit
70916d6596
2 changed files with 29 additions and 3 deletions
|
@ -1,8 +1,11 @@
|
|||
use serde_json::{Map, Value};
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{AuthController, HeedAuthStore, Result};
|
||||
|
||||
|
@ -44,4 +47,27 @@ impl AuthController {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn patch_dump_v4(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> Result<()> {
|
||||
let keys_file_src = src.as_ref().join(KEYS_PATH);
|
||||
|
||||
if !keys_file_src.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
fs::create_dir_all(&dst)?;
|
||||
let keys_file_dst = dst.as_ref().join(KEYS_PATH);
|
||||
let mut writer = File::create(&keys_file_dst)?;
|
||||
|
||||
let mut reader = BufReader::new(File::open(&keys_file_src)?).lines();
|
||||
while let Some(key) = reader.next().transpose()? {
|
||||
let mut key: Map<String, Value> = serde_json::from_str(&key)?;
|
||||
let uid = Uuid::new_v4().to_string();
|
||||
key.insert("uid".to_string(), Value::String(uid));
|
||||
serde_json::to_writer(&mut writer, &key)?;
|
||||
writer.write_all(b"\n")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue