forked from AppFlowy-IO/AppFlowy
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
frontend/rust-lib/flowy-user/src/migrations/workspace_private_v1.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::sync::Arc; | ||
|
||
use collab_folder::Folder; | ||
use collab_plugins::local_storage::kv::{KVTransactionDB, PersistenceError}; | ||
use tracing::instrument; | ||
|
||
use collab_integrate::{CollabKVAction, CollabKVDB}; | ||
use flowy_error::FlowyResult; | ||
use flowy_user_pub::entities::Authenticator; | ||
|
||
use crate::migrations::migration::UserDataMigration; | ||
use crate::migrations::util::load_collab; | ||
use flowy_user_pub::session::Session; | ||
|
||
/// Migrate the workspace: Add all the view_ids in the view_map into the private section | ||
pub struct WorkspacePrivateSectionMigration; | ||
|
||
impl UserDataMigration for WorkspacePrivateSectionMigration { | ||
fn name(&self) -> &str { | ||
"workspace_private_section_migration" | ||
} | ||
|
||
#[instrument(name = "WorkspacePrivateSectionMigration", skip_all, err)] | ||
fn run( | ||
&self, | ||
session: &Session, | ||
collab_db: &Arc<CollabKVDB>, | ||
_authenticator: &Authenticator, | ||
) -> FlowyResult<()> { | ||
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 view_ids = folder | ||
.get_workspace_views() | ||
.into_iter() | ||
.map(|view| view.id.clone()) | ||
.collect::<Vec<String>>(); | ||
|
||
if !view_ids.is_empty() { | ||
folder.add_private_view_ids(view_ids); | ||
} | ||
|
||
let encode = folder | ||
.encode_collab_v1() | ||
.map_err(|err| PersistenceError::Internal(err.into()))?; | ||
write_txn.flush_doc_with( | ||
session.user_id, | ||
&session.user_workspace.id, | ||
&encode.doc_state, | ||
&encode.state_vector, | ||
)?; | ||
} | ||
Ok(()) | ||
})?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters