fix(app): 修复 Oracle 表结构已有字段识别

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
zipgandstaff authored and GitHub committed 2026-07-01 16:05:01 +08:00
1 parent f75597b26a
commit 4da237d955
6 files changed
+488 -6

No files matched your search

@@ -20,6 +20,13 @@ pub(super) fn build_column_sql(options: &TableStructureSqlOptions, warnings: &mu
let table = qualified_table(dialect, options.schema.as_deref(), &options.table_name);
let database_label = database_label(options.database_type);
let active_columns: Vec<_> = options.columns.iter().filter(|column| !column.marked_for_drop).collect();
if dialect == StructureDialect::Oracle
&& active_columns.is_empty()
&& options.columns.iter().any(|column| column.marked_for_drop)
{
warnings.push("Oracle does not allow dropping all columns from a table. Keep at least one column or drop the table instead.".to_string());
return Vec::new();
}
let has_original_column_positions = active_columns.iter().any(|column| column.original_position.is_some());
let mut simulated_column_order =
if has_original_column_positions { original_active_column_order(&active_columns) } else { Vec::new() };
@@ -246,6 +246,52 @@ fn builds_informix_column_and_index_changes() {
);
}
#[test]
fn oracle_does_not_generate_drop_sql_for_all_columns() {
let mut id = column("id");
id.marked_for_drop = true;
id.original = Some(ColumnInfo {
name: "id".to_string(),
data_type: "varchar2(255)".to_string(),
is_nullable: true,
column_default: None,
is_primary_key: false,
extra: None,
comment: None,
});
let mut name = column("name");
name.marked_for_drop = true;
name.original = Some(ColumnInfo {
name: "name".to_string(),
data_type: "varchar2(255)".to_string(),
is_nullable: true,
column_default: None,
is_primary_key: false,
extra: None,
comment: None,
});
let result = build_table_structure_change_sql(TableStructureSqlOptions {
database_type: Some(DatabaseType::Oracle),
schema: Some("DBX_TEST".to_string()),
table_name: "test".to_string(),
columns: vec![id, name],
indexes: Vec::new(),
foreign_keys: Vec::new(),
triggers: Vec::new(),
table_comment: None,
original_table_comment: None,
});
assert_eq!(result.statements, Vec::<String>::new());
assert_eq!(
result.warnings,
vec![
"Oracle does not allow dropping all columns from a table. Keep at least one column or drop the table instead."
]
);
}
#[test]
fn iris_drop_index_includes_table_name() {
let mut old_index = index("index_id", &["ID"]);