fix(data-transfer): handle missing owner role policy and align web sync behavior
* Feat: Add PostgreSQL transfer ownership preview and resolution - Add ownership policy support for data transfers: preserve, skip, and reassign missing owners - Preview missing PostgreSQL roles before creating target schema objects - Show ownership confirmation dialog when target roles are missing - Allow users to skip ownership changes or reassign missing owners to the target connection user - Add Tauri and HTTP API support for ownership preview - Apply ownership statements according to selected policy during PostgreSQL transfers - Add Chinese localization for ownership confirmation UI * Feat: Add ownership confirmation localization - Add ownership confirmation messages for supported desktop locales - Include skip and confirm labels for ownership handling - Update transfer test requests to use Preserve ownership policy
This commit is contained in:
18 files changed
+508
-33
No files matched your search
@@ -22,6 +22,12 @@ pub struct CancelTransferRequest {
|
||||
pub transfer_id: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PreviewTransferOwnershipRequest {
|
||||
pub request: TransferRequest,
|
||||
}
|
||||
|
||||
pub async fn start_transfer(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(body): Json<StartTransferRequest>,
|
||||
@@ -95,6 +101,64 @@ pub async fn start_transfer(
|
||||
tables
|
||||
});
|
||||
let mut failed_tables: Vec<String> = Vec::new();
|
||||
|
||||
if matches!(source_db_type, dbx_core::models::connection::DatabaseType::Postgres)
|
||||
&& matches!(target_db_type, dbx_core::models::connection::DatabaseType::Postgres)
|
||||
{
|
||||
let tx_clone = tx.clone();
|
||||
match transfer::transfer_postgres_schema_dependencies(
|
||||
&app,
|
||||
&req,
|
||||
&source_pool_key,
|
||||
&target_pool_key,
|
||||
|progress| {
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx_clone.send(json);
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(e) if e == "Cancelled" => {
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: "schema dependencies".to_string(),
|
||||
table_index: 0,
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: 0,
|
||||
total_rows: None,
|
||||
status: TransferStatus::Cancelled,
|
||||
error: None,
|
||||
};
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx.send(json);
|
||||
}
|
||||
transfer::clear_cancelled(&req.transfer_id).await;
|
||||
state_clone.remove_sse_channel(&req.transfer_id).await;
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: "schema dependencies".to_string(),
|
||||
table_index: 0,
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: 0,
|
||||
total_rows: None,
|
||||
status: TransferStatus::Error,
|
||||
error: Some(e),
|
||||
};
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx.send(json);
|
||||
}
|
||||
transfer::clear_cancelled(&req.transfer_id).await;
|
||||
state_clone.remove_sse_channel(&req.transfer_id).await;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i, table) in tables.iter().enumerate() {
|
||||
if transfer::is_cancelled(&req.transfer_id).await {
|
||||
let progress = transfer::TransferProgress {
|
||||
@@ -138,14 +202,14 @@ pub async fn start_transfer(
|
||||
.await;
|
||||
|
||||
match result {
|
||||
Ok(_) => {
|
||||
Ok(rows) => {
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: table.clone(),
|
||||
table_index: i,
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: last_rows_transferred,
|
||||
total_rows: last_total_rows.or(Some(last_rows_transferred)),
|
||||
rows_transferred: rows,
|
||||
total_rows: last_total_rows.or(Some(rows)),
|
||||
status: TransferStatus::TableDone,
|
||||
error: None,
|
||||
};
|
||||
@@ -154,6 +218,24 @@ pub async fn start_transfer(
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if e == "Cancelled" {
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: table.clone(),
|
||||
table_index: i,
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: 0,
|
||||
total_rows: None,
|
||||
status: TransferStatus::Cancelled,
|
||||
error: None,
|
||||
};
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx.send(json);
|
||||
}
|
||||
transfer::clear_cancelled(&req.transfer_id).await;
|
||||
state_clone.remove_sse_channel(&req.transfer_id).await;
|
||||
return;
|
||||
}
|
||||
failed_tables.push(table.clone());
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
@@ -172,6 +254,61 @@ pub async fn start_transfer(
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(source_db_type, dbx_core::models::connection::DatabaseType::Postgres)
|
||||
&& matches!(target_db_type, dbx_core::models::connection::DatabaseType::Postgres)
|
||||
{
|
||||
let tx_clone = tx.clone();
|
||||
match transfer::transfer_postgres_schema_objects(
|
||||
&app,
|
||||
&req,
|
||||
&source_pool_key,
|
||||
&target_pool_key,
|
||||
|progress| {
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx_clone.send(json);
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(e) if e == "Cancelled" => {
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: "schema objects".to_string(),
|
||||
table_index: tables.len(),
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: 0,
|
||||
total_rows: None,
|
||||
status: TransferStatus::Cancelled,
|
||||
error: None,
|
||||
};
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx.send(json);
|
||||
}
|
||||
transfer::clear_cancelled(&req.transfer_id).await;
|
||||
state_clone.remove_sse_channel(&req.transfer_id).await;
|
||||
return;
|
||||
}
|
||||
Err(e) => {
|
||||
failed_tables.push("schema objects".to_string());
|
||||
let progress = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
table: "schema objects".to_string(),
|
||||
table_index: tables.len(),
|
||||
total_tables: tables.len(),
|
||||
rows_transferred: 0,
|
||||
total_rows: None,
|
||||
status: TransferStatus::Error,
|
||||
error: Some(e),
|
||||
};
|
||||
if let Ok(json) = serde_json::to_string(&progress) {
|
||||
let _ = tx.send(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send done
|
||||
let done = transfer::TransferProgress {
|
||||
transfer_id: req.transfer_id.clone(),
|
||||
@@ -202,6 +339,31 @@ pub async fn start_transfer(
|
||||
Ok(Json(serde_json::json!({ "transferId": transfer_id })))
|
||||
}
|
||||
|
||||
pub async fn preview_transfer_ownership(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Json(body): Json<PreviewTransferOwnershipRequest>,
|
||||
) -> Result<Json<dbx_core::transfer::TransferOwnershipPreview>, AppError> {
|
||||
let req = body.request;
|
||||
transfer::validate_transfer_target_table_names(&req).map_err(AppError)?;
|
||||
let source_db_type = transfer::get_db_type(&state.app, &req.source_connection_id).await.map_err(AppError)?;
|
||||
let target_db_type = transfer::get_db_type(&state.app, &req.target_connection_id).await.map_err(AppError)?;
|
||||
let source_pool_key =
|
||||
state.app.get_or_create_pool(&req.source_connection_id, Some(&req.source_database)).await.map_err(AppError)?;
|
||||
let target_pool_key =
|
||||
state.app.get_or_create_pool(&req.target_connection_id, Some(&req.target_database)).await.map_err(AppError)?;
|
||||
let preview = transfer::preview_transfer_ownership(
|
||||
&state.app,
|
||||
&req,
|
||||
&source_db_type,
|
||||
&target_db_type,
|
||||
&source_pool_key,
|
||||
&target_pool_key,
|
||||
)
|
||||
.await
|
||||
.map_err(AppError)?;
|
||||
Ok(Json(preview))
|
||||
}
|
||||
|
||||
pub async fn transfer_progress(
|
||||
State(state): State<Arc<WebState>>,
|
||||
Path(transfer_id): Path<String>,
|
||||
|
||||
Reference in new issue
Block a user