fix(core): include table when dropping IRIS index

This commit is contained in:
t8y2 committed 2026-06-18 11:00:19 +08:00
1 parent 8de8a85d66
commit ad0a9075b5
7 files changed
+57 -2

No files matched your search

@@ -2,6 +2,7 @@ use super::comments::build_sqlserver_index_comment_sql;
use super::dialect::{capabilities_for, database_label, database_type_for_dialect, dialect_label, StructureDialect};
use super::types::{EditableStructureIndex, TableStructureSqlOptions};
use super::util::{clean, qualified_table, quote_ident, quote_string};
use crate::models::connection::DatabaseType;
pub(super) fn build_index_sql(options: &TableStructureSqlOptions, warnings: &mut Vec<String>) -> Vec<String> {
let capabilities = capabilities_for(options.database_type);
@@ -23,7 +24,13 @@ pub(super) fn build_index_sql(options: &TableStructureSqlOptions, warnings: &mut
warnings.push(format!("Primary index \"{}\" cannot be dropped from this editor.", original.name));
continue;
}
statements.push(build_drop_index_sql(dialect, &table, options.schema.as_deref(), &original.name));
statements.push(build_drop_index_sql(
options.database_type,
dialect,
&table,
options.schema.as_deref(),
&original.name,
));
continue;
}
@@ -40,7 +47,13 @@ pub(super) fn build_index_sql(options: &TableStructureSqlOptions, warnings: &mut
warnings.push(format!("Primary index \"{}\" cannot be edited from this editor.", original.name));
continue;
}
statements.push(build_drop_index_sql(dialect, &table, options.schema.as_deref(), &original.name));
statements.push(build_drop_index_sql(
options.database_type,
dialect,
&table,
options.schema.as_deref(),
&original.name,
));
statements.extend(build_create_index_statements(
dialect,
&table,
@@ -104,11 +117,15 @@ pub(super) fn mysql_index_parts(index_type: &str) -> (String, String) {
}
pub(super) fn build_drop_index_sql(
database_type: Option<DatabaseType>,
dialect: StructureDialect,
table: &str,
schema: Option<&str>,
index_name: &str,
) -> String {
if database_type == Some(DatabaseType::Iris) {
return format!("DROP INDEX {} ON TABLE {table};", quote_ident(dialect, index_name));
}
if matches!(dialect, StructureDialect::Mysql | StructureDialect::SqlServer) {
return format!("DROP INDEX {} ON {table};", quote_ident(dialect, index_name));
}
@@ -186,6 +186,37 @@ fn builds_informix_column_and_index_changes() {
);
}
#[test]
fn iris_drop_index_includes_table_name() {
let mut old_index = index("index_id", &["ID"]);
old_index.marked_for_drop = true;
old_index.original = Some(IndexInfo {
name: "index_id".to_string(),
columns: vec!["ID".to_string()],
is_unique: false,
is_primary: false,
filter: None,
index_type: None,
included_columns: None,
comment: None,
});
let result = build_table_structure_change_sql(TableStructureSqlOptions {
database_type: Some(DatabaseType::Iris),
schema: Some("SQLUSER".to_string()),
table_name: "tb_a".to_string(),
columns: Vec::new(),
indexes: vec![old_index],
foreign_keys: Vec::new(),
triggers: Vec::new(),
table_comment: None,
original_table_comment: None,
});
assert_eq!(result.warnings, Vec::<String>::new());
assert_eq!(result.statements, vec!["DROP INDEX \"index_id\" ON TABLE \"SQLUSER\".\"tb_a\";"]);
}
#[test]
fn mysql_create_index_with_comment() {
let mut col = column("name");