fix: separate key columns from included in PG index, add varbinary(max) for SQL Server

PostgreSQL list_indexes was returning all_cols (key + included) in IndexInfo.columns,
causing DDL and UI duplication. Now only key columns are returned in columns, with
included columns correctly split via indnkeyatts.

SQL Server varbinary now handles Some(-1) to display varbinary(max).
This commit is contained in:
yavon007 2026-05-03 21:03:49 +08:00
parent 2bd7d1be1a
commit 8013a19e50
2 changed files with 8 additions and 2 deletions

View File

@ -305,10 +305,11 @@ pub async fn list_indexes(pool: &PgPool, schema: &str, table: &str) -> Result<Ve
.map(|row| {
let all_cols: Vec<String> = row.get::<Vec<String>, _>("columns");
let nkeyatts = row.get::<Option<i16>, _>("nkeyatts").unwrap_or(all_cols.len() as i16) as usize;
let key_cols = all_cols[..nkeyatts].to_vec();
let included = if nkeyatts < all_cols.len() { all_cols[nkeyatts..].to_vec() } else { vec![] };
IndexInfo {
name: row.get::<String, _>("index_name"),
columns: all_cols,
columns: key_cols,
is_unique: row.get::<bool, _>("is_unique"),
is_primary: row.get::<bool, _>("is_primary"),
filter: row.get::<Option<String>, _>("filter_expr"),

View File

@ -125,7 +125,12 @@ pub async fn get_columns(client: &mut SqlServerClient, schema: &str, table: &str
Some(n) => format!("nvarchar({n})"),
None => "nvarchar".to_string(),
},
"char" | "nchar" | "binary" | "varbinary" => match max_len {
"varbinary" => match max_len {
Some(-1) => "varbinary(max)".to_string(),
Some(n) if n > 0 => format!("varbinary({n})"),
_ => "varbinary".to_string(),
},
"char" | "nchar" | "binary" => match max_len {
Some(n) if n > 0 => format!("{base}({n})"),
_ => base,
}