fix(core): 表结构编辑中字段无长度时扩展属性变更不生成 SQL
This commit is contained in:
parent
3f7987aa59
commit
5aa5ed9cee
|
|
@ -6,6 +6,7 @@ use super::util::{
|
|||
clean, format_default_for_sql, normalize_default, original_comment, original_default, qualified_table, quote_ident,
|
||||
quote_string,
|
||||
};
|
||||
use crate::table_structure_sql::ColumnExtra;
|
||||
|
||||
pub fn build_single_column_alter_sql(options: SingleColumnAlterSqlOptions) -> TableStructureSqlResult {
|
||||
let capabilities = capabilities_for(options.database_type);
|
||||
|
|
@ -88,12 +89,20 @@ pub fn build_single_column_alter_sql(options: SingleColumnAlterSqlOptions) -> Ta
|
|||
TableStructureSqlResult { statements, warnings }
|
||||
}
|
||||
|
||||
fn is_column_extra_empty(extra: &ColumnExtra) -> bool {
|
||||
!extra.auto_increment.unwrap_or(false)
|
||||
&& !extra.on_update_current_timestamp.unwrap_or(false)
|
||||
&& extra.identity.is_none()
|
||||
}
|
||||
|
||||
pub(super) fn has_column_extra_change(column: &EditableStructureColumn) -> bool {
|
||||
let Some(original) = &column.original else { return false };
|
||||
let current_extra = column.extra.as_ref();
|
||||
match (current_extra, original.extra.as_deref()) {
|
||||
// Neither has extra → no change
|
||||
(None, None | Some("")) => false,
|
||||
// Current extra is empty (all None) → no effective extra
|
||||
(Some(curr), _) if is_column_extra_empty(curr) => false,
|
||||
// Extra added or removed
|
||||
(Some(_), None | Some("")) => true,
|
||||
(None, Some(_)) => true,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use super::column_alter::{
|
||||
build_clickhouse_existing_column_sql, build_h2_existing_column_sql, build_mysql_existing_column_sql,
|
||||
build_oracle_like_existing_column_sql, build_postgres_existing_column_sql, build_sqlite_existing_column_sql,
|
||||
build_sqlserver_existing_column_sql, has_existing_column_attribute_change,
|
||||
build_sqlserver_existing_column_sql, has_column_extra_change, has_existing_column_attribute_change,
|
||||
};
|
||||
use super::column_format::column_definition;
|
||||
use super::comments::build_sqlserver_column_comment_sql;
|
||||
|
|
@ -64,7 +64,7 @@ pub(super) fn build_column_sql(options: &TableStructureSqlOptions, warnings: &mu
|
|||
continue;
|
||||
}
|
||||
|
||||
if !has_existing_column_attribute_change(column) && !has_position_change {
|
||||
if !has_existing_column_attribute_change(column) && !has_column_extra_change(column) && !has_position_change {
|
||||
continue;
|
||||
}
|
||||
let original = column.original.as_ref().unwrap();
|
||||
|
|
@ -72,7 +72,8 @@ pub(super) fn build_column_sql(options: &TableStructureSqlOptions, warnings: &mu
|
|||
let has_attribute_change = column.data_type.trim() != original.data_type.trim()
|
||||
|| column.is_nullable != original.is_nullable
|
||||
|| normalize_default(Some(&column.default_value)) != original_default(column)
|
||||
|| clean(&column.comment) != original_comment(column);
|
||||
|| clean(&column.comment) != original_comment(column)
|
||||
|| has_column_extra_change(column);
|
||||
if has_position_change && !capabilities.reorder_column {
|
||||
warnings.push(format!("Reordering columns is not supported for {database_label} from this editor."));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue