mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: Get started doc migration (#3102)
* feat: migrate empty document * chore: update collab rev * chore: fmt
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
use crate::user::migration_test::util::unzip_history_user_db;
|
||||
use flowy_core::DEFAULT_NAME;
|
||||
use flowy_folder2::entities::ViewLayoutPB;
|
||||
use flowy_test::FlowyCoreTest;
|
||||
|
||||
#[tokio::test]
|
||||
async fn migrate_historical_empty_document_test() {
|
||||
let (cleaner, user_db_path) = unzip_history_user_db("historical_empty_document").unwrap();
|
||||
let test = FlowyCoreTest::new_with_user_data_path(
|
||||
user_db_path.to_str().unwrap(),
|
||||
DEFAULT_NAME.to_string(),
|
||||
);
|
||||
|
||||
let views = test.get_all_workspace_views().await;
|
||||
assert_eq!(views.len(), 3);
|
||||
for view in views {
|
||||
assert_eq!(view.layout, ViewLayoutPB::Document);
|
||||
let doc = test.open_document(view.id).await;
|
||||
println!("doc: {:?}", doc.data);
|
||||
}
|
||||
|
||||
drop(cleaner);
|
||||
}
|
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
mod document_test;
|
||||
mod util;
|
@ -0,0 +1,64 @@
|
||||
use nanoid::nanoid;
|
||||
use std::fs::{create_dir_all, File};
|
||||
use std::io::copy;
|
||||
use std::path::{Path, PathBuf};
|
||||
use zip::ZipArchive;
|
||||
|
||||
pub fn unzip_history_user_db(folder_name: &str) -> std::io::Result<(Cleaner, PathBuf)> {
|
||||
// Open the zip file
|
||||
let zip_file_path = format!(
|
||||
"./tests/user/migration_test/history_user_db/{}.zip",
|
||||
folder_name
|
||||
);
|
||||
let reader = File::open(zip_file_path)?;
|
||||
let output_folder_path = format!(
|
||||
"./tests/user/migration_test/history_user_db/unit_test_{}",
|
||||
nanoid!(6)
|
||||
);
|
||||
|
||||
// Create a ZipArchive from the file
|
||||
let mut archive = ZipArchive::new(reader)?;
|
||||
|
||||
// Iterate through each file in the zip
|
||||
for i in 0..archive.len() {
|
||||
let mut file = archive.by_index(i)?;
|
||||
let output_path = Path::new(&output_folder_path).join(file.mangled_name());
|
||||
|
||||
if file.name().ends_with('/') {
|
||||
// Create directory
|
||||
create_dir_all(&output_path)?;
|
||||
} else {
|
||||
// Write file
|
||||
if let Some(p) = output_path.parent() {
|
||||
if !p.exists() {
|
||||
create_dir_all(p)?;
|
||||
}
|
||||
}
|
||||
let mut outfile = File::create(&output_path)?;
|
||||
copy(&mut file, &mut outfile)?;
|
||||
}
|
||||
}
|
||||
let path = format!("{}/{}", output_folder_path, folder_name);
|
||||
Ok((
|
||||
Cleaner::new(PathBuf::from(output_folder_path)),
|
||||
PathBuf::from(path),
|
||||
))
|
||||
}
|
||||
|
||||
pub struct Cleaner(PathBuf);
|
||||
|
||||
impl Cleaner {
|
||||
pub fn new(dir: PathBuf) -> Self {
|
||||
Cleaner(dir)
|
||||
}
|
||||
|
||||
fn cleanup(dir: &PathBuf) {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Cleaner {
|
||||
fn drop(&mut self) {
|
||||
Self::cleanup(&self.0)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user