fix: sort tables by FK dependency in transfer and export
This commit is contained in:
1 parent
71db24813e
commit
c4c427fb67
11 files changed
+292
-6
No files matched your search
@@ -454,9 +454,37 @@ pub fn build_export_sql_insert(
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn build_database_sql_export(
|
||||
options: dbx_core::database_export::BuildDatabaseSqlExportOptions,
|
||||
pub async fn build_database_sql_export(
|
||||
state: tauri::State<'_, std::sync::Arc<dbx_core::connection::AppState>>,
|
||||
mut options: dbx_core::database_export::BuildDatabaseSqlExportOptions,
|
||||
) -> Result<String, String> {
|
||||
// Sort tables by FK dependency when connection info is available.
|
||||
if let (Some(ref conn_id), Some(ref database), Some(ref schema)) =
|
||||
(&options.connection_id, &options.database, &options.schema)
|
||||
{
|
||||
if options.tables.len() > 1 {
|
||||
let table_names: Vec<String> = options.tables.iter().filter_map(|t| t.table_name.clone()).collect();
|
||||
if table_names.len() > 1 {
|
||||
if let Ok(sorted_names) = dbx_core::transfer::sort_tables_by_fk_dependency(
|
||||
&state,
|
||||
conn_id,
|
||||
database,
|
||||
schema,
|
||||
&table_names,
|
||||
true,
|
||||
)
|
||||
.await
|
||||
{
|
||||
options.tables.sort_by_key(|t| {
|
||||
sorted_names
|
||||
.iter()
|
||||
.position(|n| Some(n.as_str()) == t.table_name.as_deref())
|
||||
.unwrap_or(usize::MAX)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dbx_core::database_export::build_database_sql_export(options)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user