fix(oracle): 修复时间字段编辑和表结构修改报错

Co-authored-by: staff <staff@qimaos-MacBook-Pro.local>
This commit is contained in:
zipgandstaff authored and GitHub committed 2026-07-02 12:09:05 +08:00
1 parent 24d952dc12
commit d9f50644eb
4 files changed
+143 -21

No files matched your search

@@ -360,12 +360,6 @@ pub(super) fn build_oracle_like_existing_column_sql(
if type_changed || nullable_changed || default_changed {
let data_type = column_data_type(dialect, column);
let mut parts = vec![quote_ident(dialect, &current_name), data_type];
// Always include nullability so the statement is self-contained (required by Dameng).
if !column.is_nullable {
parts.push("NOT NULL".to_string());
} else {
parts.push("NULL".to_string());
}
let default_value = normalize_default(Some(&column.default_value));
if !default_value.is_empty() {
parts.push(format!("DEFAULT {}", format_default_for_sql(dialect, &column.data_type, &default_value)));
@@ -373,6 +367,13 @@ pub(super) fn build_oracle_like_existing_column_sql(
// User cleared the default — explicitly drop it.
parts.push("DEFAULT NULL".to_string());
}
if nullable_changed {
if column.is_nullable {
parts.push("NULL".to_string());
} else {
parts.push("NOT NULL".to_string());
}
}
statements.push(format!("ALTER TABLE {table} MODIFY ({});", parts.join(" ")));
}
if clean(&column.comment) != original_comment(column) {
@@ -292,6 +292,60 @@ fn oracle_does_not_generate_drop_sql_for_all_columns() {
);
}
#[test]
fn oracle_timestamp_default_precedes_nullability_in_modify_sql() {
let mut col = column("time");
col.data_type = "TIMESTAMP(6)".to_string();
col.default_value = "CURRENT_TIMESTAMP".to_string();
col.original = Some(ColumnInfo {
name: "time".to_string(),
data_type: "TIMESTAMP(6)".to_string(),
is_nullable: true,
column_default: None,
is_primary_key: false,
extra: None,
comment: Some(String::new()),
});
let result = build_single_column_alter_sql(SingleColumnAlterSqlOptions {
database_type: Some(DatabaseType::Oracle),
schema: Some("DBX_TEST".to_string()),
table_name: "test".to_string(),
column: col,
});
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(
result.statements,
vec!["ALTER TABLE \"DBX_TEST\".\"test\" MODIFY (\"time\" TIMESTAMP(6) DEFAULT CURRENT_TIMESTAMP);"]
);
}
#[test]
fn oracle_timestamp_precision_change_does_not_repeat_unchanged_nullability() {
let mut col = column("time");
col.data_type = "TIMESTAMP(9)".to_string();
col.original = Some(ColumnInfo {
name: "time".to_string(),
data_type: "TIMESTAMP(6)".to_string(),
is_nullable: true,
column_default: None,
is_primary_key: false,
extra: None,
comment: Some(String::new()),
});
let result = build_single_column_alter_sql(SingleColumnAlterSqlOptions {
database_type: Some(DatabaseType::Oracle),
schema: Some("DBX_TEST".to_string()),
table_name: "test".to_string(),
column: col,
});
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(result.statements, vec!["ALTER TABLE \"DBX_TEST\".\"test\" MODIFY (\"time\" TIMESTAMP(9));"]);
}
#[test]
fn iris_drop_index_includes_table_name() {
let mut old_index = index("index_id", &["ID"]);