Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(transfer): place reused Oracle table DDL in the target's default tablespace (#11966)

Jeffa80d12da2d45
diff --git a/crates/dbx-core/src/data/transfer/ddl_plan.rs b/crates/dbx-core/src/data/transfer/ddl_plan.rs
index 075574ac6d..aea9a9623a 100644
--- a/crates/dbx-core/src/data/transfer/ddl_plan.rs
+++ b/crates/dbx-core/src/data/transfer/ddl_plan.rs
@@ -146,13 +146,12 @@ pub(super) async fn prepare_table_ddl(
}
}
} else {
- match crate::schema::get_table_ddl_core(
+ match crate::schema::get_table_transfer_ddl_core(
state,
&request.source_connection_id,
&request.source_database,
&request.source_schema,
table,
- None,
)
.await
{
diff --git a/crates/dbx-core/src/schema/mod.rs b/crates/dbx-core/src/schema/mod.rs
index 6384723e5f..6daaae888c 100644
--- a/crates/dbx-core/src/schema/mod.rs
+++ b/crates/dbx-core/src/schema/mod.rs
@@ -9592,7 +9592,9 @@ pub async fn get_table_owner_core(
/// they already iterate every relation themselves. A selected table structure
/// export and interactive display both recurse through the PostgreSQL
/// partition tree, while only display includes access statements. Oracle
-/// exports additionally request portable DDL normalization.
+/// exports and transfers additionally request portable DDL normalization: a
+/// transfer target must not inherit the source tablespaces, which the target
+/// user may have no quota on (#11939).
#[derive(Clone, Copy)]
struct TableDdlOptions {
include_postgres_access: bool,
@@ -9614,6 +9616,12 @@ impl TableDdlOptions {
portable_oracle: true,
include_sqlserver_temporal: false,
};
+ const TRANSFER: Self = Self {
+ include_postgres_access: false,
+ include_partitions: false,
+ portable_oracle: true,
+ include_sqlserver_temporal: false,
+ };
const EXPORT: Self = Self {
include_postgres_access: false,
include_partitions: true,
@@ -9670,6 +9678,27 @@ pub async fn get_table_export_ddl_core(
.await
}
+/// Source DDL for a table transfer that reuses it on the target.
+pub(crate) async fn get_table_transfer_ddl_core(
+ state: &AppState,
+ connection_id: &str,
+ database: &str,
+ schema: &str,
+ table: &str,
+) -> Result<String, String> {
+ get_table_ddl_core_with_options(
+ state,
+ connection_id,
+ database,
+ schema,
+ table,
+ None,
+ TableDdlOptions::TRANSFER,
+ None,
+ )
+ .await
+}
+
pub(crate) async fn get_table_relation_export_ddl_core_for_session(
state: &AppState,
connection_id: &str,
@@ -13029,6 +13058,12 @@ mod ddl_tests {
assert_table_ddl_options(TableDdlOptions::DISPLAY, true, false, true);
}
+ #[test]
+ fn table_transfer_requests_portable_oracle_ddl_for_one_relation() {
+ // Reused Oracle DDL must not carry source tablespaces into the target (#11939).
+ assert_table_ddl_options(TableDdlOptions::TRANSFER, false, true, false);
+ }
+
#[test]
fn postgres_table_ddl_includes_column_comments() {
let mut display_name = column("display_name", "text");
diff --git a/crates/dbx-core/tests/live_oracle_transfer.rs b/crates/dbx-core/tests/live_oracle_transfer.rs
index 56e6dab5d2..61d71fb668 100644
--- a/crates/dbx-core/tests/live_oracle_transfer.rs
+++ b/crates/dbx-core/tests/live_oracle_transfer.rs
@@ -169,3 +169,119 @@ async fn live_oracle_transfer_creates_table_with_index_comment_and_trigger() {
assert_eq!(cells(&ids.unwrap()), vec!["100".to_string(), "105".to_string()]);
assert_eq!(cells(&source_triggers.unwrap()), vec!["1".to_string()]);
}
+
+/// Like the test above, but the two users must have different default tablespaces and
+/// the target user must have no quota on the source user's default tablespace.
+#[tokio::test]
+#[ignore = "requires DBX_LIVE_ORACLE_SOURCE_USER and DBX_LIVE_ORACLE_TARGET_USER with separate default tablespaces"]
+async fn live_oracle_transfer_places_tables_in_target_default_tablespace() {
+ let suffix = uuid::Uuid::new_v4().simple().to_string()[..8].to_uppercase();
+ let dir = std::env::temp_dir().join(format!("dbx-live-oracle-transfer-ts-{suffix}"));
+ std::fs::create_dir_all(&dir).unwrap();
+ let storage = dbx_core::persistence::test_storage::open(&dir.join("storage.db")).await.unwrap();
+ let state = Arc::new(AppState::new(storage));
+ let service = std::env::var("DBX_LIVE_ORACLE_SERVICE").unwrap();
+ let source_schema =
+ std::env::var("DBX_LIVE_ORACLE_SOURCE_USER").expect("DBX_LIVE_ORACLE_SOURCE_USER").to_uppercase();
+ let target_schema =
+ std::env::var("DBX_LIVE_ORACLE_TARGET_USER").expect("DBX_LIVE_ORACLE_TARGET_USER").to_uppercase();
+ let source_id = format!("live-oracle-transfer-ts-src-{suffix}");
+ let target_id = format!("live-oracle-transfer-ts-dst-{suffix}");
+ state.configs.write().await.insert(source_id.clone(), live_oracle_config(&source_id, &source_schema));
+ state.configs.write().await.insert(target_id.clone(), live_oracle_config(&target_id, &target_schema));
+
+ let filled = format!("DBX_TRANSFER_TS_FILLED_{suffix}");
+ let empty = format!("DBX_TRANSFER_TS_EMPTY_{suffix}");
+ let run = |connection_id: String, schema: String, sql: String| {
+ let state = state.clone();
+ let service = service.clone();
+ async move { execute_sql_statement(&state, &connection_id, &service, &sql, Some(&schema), None).await }
+ };
+ let source = |sql: String| run(source_id.clone(), source_schema.clone(), sql);
+ let target = |sql: String| run(target_id.clone(), target_schema.clone(), sql);
+ let drop_all = [format!("DROP TABLE {filled} PURGE"), format!("DROP TABLE {empty} PURGE")];
+ for sql in &drop_all {
+ let _ = source(sql.clone()).await;
+ let _ = target(sql.clone()).await;
+ }
+
+ let default_tablespace = "SELECT DEFAULT_TABLESPACE FROM USER_USERS".to_string();
+ let source_tablespace = cells(&source(default_tablespace.clone()).await.unwrap());
+ let target_tablespace = cells(&target(default_tablespace).await.unwrap());
+ assert_ne!(source_tablespace, target_tablespace, "the users must have different default tablespaces");
+
+ for sql in [
+ format!("CREATE TABLE {filled} (ID NUMBER PRIMARY KEY, NOTE VARCHAR2(50), BODY CLOB)"),
+ format!("CREATE INDEX {filled}_NOTE_IX ON {filled} (NOTE)"),
+ format!("INSERT INTO {filled} VALUES (1, 'first', 'body')"),
+ format!("CREATE TABLE {empty} (ID NUMBER PRIMARY KEY, BODY CLOB)"),
+ ] {
+ source(sql).await.expect("source setup");
+ }
+
+ let request = TransferRequest {
+ table_filters: Default::default(),
+ transfer_id: format!("live-oracle-transfer-ts-{suffix}"),
+ source_connection_id: source_id.clone(),
+ source_database: service.clone(),
+ source_schema: source_schema.clone(),
+ source_catalog: None,
+ target_connection_id: target_id.clone(),
+ target_database: service.clone(),
+ target_schema: target_schema.clone(),
+ target_catalog: None,
+ tables: vec![filled.clone(), empty.clone()],
+ create_table: true,
+ drop_target_before_create: false,
+ drop_target_confirmed: false,
+ content: TransferContent::StructureAndData,
+ objects: None,
+ mode: TransferMode::Append,
+ target_table_name_case: TransferTableNameCase::Preserve,
+ quote_target_column_names: true,
+ ownership_policy: TransferOwnershipPolicy::Preserve,
+ batch_size: 100,
+ };
+ let source_pool = ensure_transfer_pool(&state, &source_id, &service, None).await.unwrap();
+ let target_pool = ensure_transfer_pool(&state, &target_id, &service, None).await.unwrap();
+ let mut results = Vec::new();
+ for (index, table) in [&filled, &empty].into_iter().enumerate() {
+ results.push(
+ transfer_table(
+ &state,
+ &request,
+ table,
+ index,
+ &DatabaseType::Oracle,
+ &DatabaseType::Oracle,
+ &source_pool,
+ &target_pool,
+ &Default::default(),
+ &mut Vec::new(),
+ None,
+ |_| {},
+ )
+ .await,
+ );
+ }
+ let in_tables = format!("('{filled}', '{empty}')");
+ let segment_tablespaces = target(format!(
+ "SELECT DISTINCT TABLESPACE_NAME FROM (\
+ SELECT TABLESPACE_NAME FROM USER_TABLES WHERE TABLE_NAME IN {in_tables} \
+ UNION ALL SELECT TABLESPACE_NAME FROM USER_INDEXES WHERE TABLE_NAME IN {in_tables} \
+ UNION ALL SELECT TABLESPACE_NAME FROM USER_LOBS WHERE TABLE_NAME IN {in_tables})"
+ ))
+ .await;
+ // The empty table has no segment yet, so only a write proves the target can use it.
+ let insert = target(format!("INSERT INTO {empty} VALUES (1, 'body')")).await;
+
+ for sql in &drop_all {
+ let _ = source(sql.clone()).await;
+ let _ = target(sql.clone()).await;
+ }
+ let _ = std::fs::remove_dir_all(dir);
+
+ assert_eq!(results, vec![Ok(1), Ok(0)]);
+ assert_eq!(cells(&segment_tablespaces.unwrap()), target_tablespace);
+ insert.expect("the empty table accepts rows in the target tablespace");
+}