fix(core): 表结构编辑中字段无长度时扩展属性变更不生成 SQL
This commit is contained in:
1 parent
3f7987aa59
commit
5aa5ed9cee
2 files changed
+13
-3
No files matched your search
@@ -6,6 +6,7 @@ use super::util::{
|
|||||||
clean, format_default_for_sql, normalize_default, original_comment, original_default, qualified_table, quote_ident,
|
clean, format_default_for_sql, normalize_default, original_comment, original_default, qualified_table, quote_ident,
|
||||||
quote_string,
|
quote_string,
|
||||||
};
|
};
|
||||||
|
use crate::table_structure_sql::ColumnExtra;
|
||||||
|
|
||||||
pub fn build_single_column_alter_sql(options: SingleColumnAlterSqlOptions) -> TableStructureSqlResult {
|
pub fn build_single_column_alter_sql(options: SingleColumnAlterSqlOptions) -> TableStructureSqlResult {
|
||||||
let capabilities = capabilities_for(options.database_type);
|
let capabilities = capabilities_for(options.database_type);
|
||||||
@@ -88,12 +89,20 @@ pub fn build_single_column_alter_sql(options: SingleColumnAlterSqlOptions) -> Ta
|
|||||||
TableStructureSqlResult { statements, warnings }
|
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 {
|
pub(super) fn has_column_extra_change(column: &EditableStructureColumn) -> bool {
|
||||||
let Some(original) = &column.original else { return false };
|
let Some(original) = &column.original else { return false };
|
||||||
let current_extra = column.extra.as_ref();
|
let current_extra = column.extra.as_ref();
|
||||||
match (current_extra, original.extra.as_deref()) {
|
match (current_extra, original.extra.as_deref()) {
|
||||||
// Neither has extra → no change
|
// Neither has extra → no change
|
||||||
(None, None | Some("")) => false,
|
(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
|
// Extra added or removed
|
||||||
(Some(_), None | Some("")) => true,
|
(Some(_), None | Some("")) => true,
|
||||||
(None, Some(_)) => true,
|
(None, Some(_)) => true,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use super::column_alter::{
|
use super::column_alter::{
|
||||||
build_clickhouse_existing_column_sql, build_h2_existing_column_sql, build_mysql_existing_column_sql,
|
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_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::column_format::column_definition;
|
||||||
use super::comments::build_sqlserver_column_comment_sql;
|
use super::comments::build_sqlserver_column_comment_sql;
|
||||||
@@ -64,7 +64,7 @@ pub(super) fn build_column_sql(options: &TableStructureSqlOptions, warnings: &mu
|
|||||||
continue;
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
let original = column.original.as_ref().unwrap();
|
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()
|
let has_attribute_change = column.data_type.trim() != original.data_type.trim()
|
||||||
|| column.is_nullable != original.is_nullable
|
|| column.is_nullable != original.is_nullable
|
||||||
|| normalize_default(Some(&column.default_value)) != original_default(column)
|
|| 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 {
|
if has_position_change && !capabilities.reorder_column {
|
||||||
warnings.push(format!("Reordering columns is not supported for {database_label} from this editor."));
|
warnings.push(format!("Reordering columns is not supported for {database_label} from this editor."));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user