diff --git a/crates/dbx-core/src/transfer.rs b/crates/dbx-core/src/transfer.rs index 0bdca50b45..ba36c6d268 100644 --- a/crates/dbx-core/src/transfer.rs +++ b/crates/dbx-core/src/transfer.rs @@ -1444,6 +1444,18 @@ fn max_transfer_write_rows(db_type: &DatabaseType, mode: &TransferMode) -> usize } } +fn can_reuse_source_table_ddl( + source_db_type: &DatabaseType, + target_db_type: &DatabaseType, + preserves_target_table_name: bool, +) -> bool { + preserves_target_table_name + && !matches!(target_db_type, DatabaseType::ClickHouse) + && ((source_db_type == target_db_type) + || (is_mysql_family_target(source_db_type) && is_mysql_family_target(target_db_type)) + || (is_postgres_family_target(source_db_type) && is_postgres_family_target(target_db_type))) +} + #[allow(clippy::too_many_arguments)] fn generate_transfer_write_sql( mode: &TransferMode, @@ -2977,10 +2989,8 @@ where .await .map_err(|e| format!("Failed to ensure schema exists: {e}"))?; } - let can_reuse_source_ddl = preserves_target_table_name - && ((source_db_type == target_db_type) - || (is_mysql_family_target(source_db_type) && is_mysql_family_target(target_db_type)) - || (is_postgres_family_target(source_db_type) && is_postgres_family_target(target_db_type))); + let can_reuse_source_ddl = + can_reuse_source_table_ddl(source_db_type, target_db_type, preserves_target_table_name); let ddl = if can_reuse_source_ddl { crate::schema::get_table_ddl_core( &state, @@ -3848,6 +3858,13 @@ mod tests { assert!(!ddl.contains("PRIMARY KEY")); } + #[test] + fn clickhouse_transfer_does_not_reuse_source_table_ddl() { + assert!(!can_reuse_source_table_ddl(&DatabaseType::ClickHouse, &DatabaseType::ClickHouse, true)); + assert!(can_reuse_source_table_ddl(&DatabaseType::Postgres, &DatabaseType::Postgres, true)); + assert!(!can_reuse_source_table_ddl(&DatabaseType::Postgres, &DatabaseType::Postgres, false)); + } + #[test] fn hive_create_table_uses_hive_friendly_columns() { let cols = vec![