chore: fix rust test

This commit is contained in:
Nathan 2025-04-21 13:07:50 +08:00
parent 7885cb80f4
commit 2cf96a2ce3
4 changed files with 53 additions and 18 deletions

View file

@ -159,7 +159,6 @@ impl DocumentManager {
format!("document {} already exists", doc_id),
))
} else {
info!("create document {}", doc_id);
let encoded_collab = doc_state_from_document_data(doc_id, data).await?;
self
.persistence()?

View file

@ -4,7 +4,7 @@ use crate::sql::select_user_workspace;
use flowy_error::{FlowyError, FlowyResult};
use flowy_sqlite::schema::user_table;
use flowy_sqlite::{prelude::*, DBConnection, ExpressionMethods, RunQueryDsl};
use tracing::trace;
use tracing::{trace, warn};
/// The order of the fields in the struct must be the same as the order of the fields in the table.
/// Check out the [schema.rs] for table schema.
@ -92,14 +92,7 @@ pub fn update_user_profile(
Ok(())
}
pub fn select_user_profile(
uid: i64,
workspace_id: &str,
conn: &mut SqliteConnection,
) -> Result<UserProfile, FlowyError> {
let workspace = select_user_workspace(workspace_id, conn)?;
let workspace_auth_type = AuthType::from(workspace.workspace_type);
fn select_user_table_row(uid: i64, conn: &mut SqliteConnection) -> Result<UserTable, FlowyError> {
let row = user_table::dsl::user_table
.filter(user_table::id.eq(&uid.to_string()))
.first::<UserTable>(conn)
@ -109,6 +102,17 @@ pub fn select_user_profile(
uid, err
))
})?;
Ok(row)
}
pub fn select_user_profile(
uid: i64,
workspace_id: &str,
conn: &mut SqliteConnection,
) -> Result<UserProfile, FlowyError> {
let workspace = select_user_workspace(workspace_id, conn)?;
let workspace_auth_type = AuthType::from(workspace.workspace_type);
let row = select_user_table_row(uid, conn)?;
let user = UserProfile {
uid: row.id.parse::<i64>().unwrap_or(0),
@ -124,6 +128,28 @@ pub fn select_user_profile(
Ok(user)
}
pub fn select_workspace_auth_type(
uid: i64,
workspace_id: &str,
conn: &mut SqliteConnection,
) -> Result<AuthType, FlowyError> {
match select_user_workspace(workspace_id, conn) {
Ok(workspace) => Ok(AuthType::from(workspace.workspace_type)),
Err(err) => {
if err.is_record_not_found() {
let row = select_user_table_row(uid, conn)?;
warn!(
"user user auth type:{} as workspace auth type",
row.auth_type
);
Ok(AuthType::from(row.auth_type))
} else {
Err(err)
}
},
}
}
pub fn upsert_user(user: UserTable, mut conn: DBConnection) -> FlowyResult<()> {
conn.immediate_transaction(|conn| {
// delete old user if exists

View file

@ -36,7 +36,7 @@ use std::collections::{HashMap, HashSet};
use collab_document::blocks::TextDelta;
use collab_document::document::Document;
use flowy_user_pub::sql::select_user_profile;
use flowy_user_pub::sql::{select_user_profile, select_workspace_auth_type};
use semver::Version;
use serde_json::json;
use std::ops::{Deref, DerefMut};
@ -101,15 +101,25 @@ pub(crate) fn prepare_import(
CollabKVDB::open(collab_db_path)
.map_err(|err| anyhow!("[AppflowyData]: open import collab db failed: {:?}", err))?,
);
let imported_user = select_user_profile(
let mut conn = imported_sqlite_db.get_connection()?;
let imported_workspace_auth_type = select_user_profile(
imported_session.user_id,
&imported_session.user_workspace.id,
&mut *imported_sqlite_db.get_connection()?,
)?;
&mut conn,
)
.map(|v| v.workspace_auth_type)
.or_else(|_| {
select_workspace_auth_type(
imported_session.user_id,
&imported_session.user_workspace.id,
&mut conn,
)
})?;
run_collab_data_migration(
&imported_session,
&imported_user,
&imported_workspace_auth_type,
imported_collab_db.clone(),
imported_sqlite_db.get_pool(),
other_store_preferences.clone(),

View file

@ -253,7 +253,7 @@ impl UserManager {
(Ok(collab_db), Ok(sqlite_pool)) => {
run_collab_data_migration(
&session,
&user,
&user.auth_type,
collab_db,
sqlite_pool,
self.store_preferences.clone(),
@ -869,7 +869,7 @@ fn mark_all_migrations_as_applied(sqlite_pool: &Arc<ConnectionPool>) {
pub(crate) fn run_collab_data_migration(
session: &Session,
user: &UserProfile,
auth_type: &AuthType,
collab_db: Arc<CollabKVDB>,
sqlite_pool: Arc<ConnectionPool>,
kv: Arc<KVStorePreferences>,
@ -878,7 +878,7 @@ pub(crate) fn run_collab_data_migration(
let migrations = collab_migration_list();
match UserLocalDataMigration::new(session.clone(), collab_db, sqlite_pool, kv).run(
migrations,
&user.auth_type,
auth_type,
app_version,
) {
Ok(applied_migrations) => {