2023-12-26 02:03:42 +08:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use collab_folder::Folder;
|
2024-02-25 07:49:44 +08:00
|
|
|
use collab_plugins::local_storage::kv::{KVTransactionDB, PersistenceError};
|
2023-12-26 02:03:42 +08:00
|
|
|
use tracing::instrument;
|
|
|
|
|
|
2024-01-05 00:05:38 +08:00
|
|
|
use collab_integrate::{CollabKVAction, CollabKVDB};
|
2024-02-25 07:49:44 +08:00
|
|
|
use flowy_error::FlowyResult;
|
2024-01-11 14:42:03 +08:00
|
|
|
use flowy_user_pub::entities::Authenticator;
|
2023-12-26 02:03:42 +08:00
|
|
|
|
|
|
|
|
use crate::migrations::migration::UserDataMigration;
|
|
|
|
|
use crate::migrations::util::load_collab;
|
2024-01-30 05:36:27 +08:00
|
|
|
use flowy_user_pub::session::Session;
|
2023-12-26 02:03:42 +08:00
|
|
|
|
2023-12-27 11:42:39 +08:00
|
|
|
/// Migrate the workspace: { trash: [view_id] } to { trash: { uid: [view_id] } }
|
2023-12-26 02:03:42 +08:00
|
|
|
pub struct WorkspaceTrashMapToSectionMigration;
|
|
|
|
|
|
|
|
|
|
impl UserDataMigration for WorkspaceTrashMapToSectionMigration {
|
|
|
|
|
fn name(&self) -> &str {
|
|
|
|
|
"workspace_trash_map_to_section_migration"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[instrument(name = "WorkspaceTrashMapToSectionMigration", skip_all, err)]
|
|
|
|
|
fn run(
|
|
|
|
|
&self,
|
|
|
|
|
session: &Session,
|
2024-01-05 00:05:38 +08:00
|
|
|
collab_db: &Arc<CollabKVDB>,
|
2023-12-26 02:03:42 +08:00
|
|
|
_authenticator: &Authenticator,
|
|
|
|
|
) -> FlowyResult<()> {
|
2024-02-25 07:49:44 +08:00
|
|
|
collab_db.with_write_txn(|write_txn| {
|
|
|
|
|
if let Ok(collab) = load_collab(session.user_id, write_txn, &session.user_workspace.id) {
|
|
|
|
|
let folder = Folder::open(session.user_id, collab, None)
|
|
|
|
|
.map_err(|err| PersistenceError::Internal(err.into()))?;
|
|
|
|
|
let trash_ids = folder
|
|
|
|
|
.get_trash_v1()
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|fav| fav.id)
|
|
|
|
|
.collect::<Vec<String>>();
|
|
|
|
|
|
|
|
|
|
if !trash_ids.is_empty() {
|
2024-03-22 16:15:18 +07:00
|
|
|
folder.add_trash_view_ids(trash_ids);
|
2024-01-05 00:05:38 +08:00
|
|
|
}
|
2024-02-25 07:49:44 +08:00
|
|
|
|
|
|
|
|
let encode = folder.encode_collab_v1();
|
|
|
|
|
write_txn.flush_doc_with(
|
|
|
|
|
session.user_id,
|
|
|
|
|
&session.user_workspace.id,
|
|
|
|
|
&encode.doc_state,
|
|
|
|
|
&encode.state_vector,
|
|
|
|
|
)?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
})?;
|
2023-12-26 02:03:42 +08:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|