25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix: guard index column splits, restrict INCLUDE/WHERE by db, unify index type dropdowns
yavon007a59494e4c4b9
diff --git a/src-tauri/src/db/mysql.rs b/src-tauri/src/db/mysql.rsindex 412c22a8d2..c7d8c8a366 100644--- a/src-tauri/src/db/mysql.rs+++ b/src-tauri/src/db/mysql.rs@@ -352,7 +352,7 @@ pub async fn list_indexes(pool: &MySqlPool, database: &str, table: &str) -> Resulet cols_str = get_str_by_name(row, "columns");IndexInfo {name: get_str_by_name(row, "INDEX_NAME"),- columns: cols_str.split(',').map(|s| s.to_string()).collect(),+ columns: cols_str.split(',').filter(|s| !s.is_empty()).map(|s| s.to_string()).collect(),is_unique: row.get::<bool, _>("is_unique"),is_primary: row.get::<bool, _>("is_primary"),filter: None,diff --git a/src-tauri/src/db/oracle_driver.rs b/src-tauri/src/db/oracle_driver.rsindex e6d1eccf8d..2ae7d87d23 100644--- a/src-tauri/src/db/oracle_driver.rs+++ b/src-tauri/src/db/oracle_driver.rs@@ -150,7 +150,7 @@ pub async fn list_indexes(conn: &OracleClient, schema: &str, table: &str) -> Reslet cols_str = row.get_string(1).unwrap_or("");IndexInfo {name: row.get_string(0).unwrap_or("").to_string(),- columns: cols_str.split(',').map(|s| s.to_string()).collect(),+ columns: cols_str.split(',').filter(|s| !s.is_empty()).map(|s| s.to_string()).collect(),is_unique: row.get_string(2).unwrap_or("") == "UNIQUE",is_primary: row.get_i64(3).unwrap_or(0) == 1,filter: None,diff --git a/src-tauri/src/db/postgres.rs b/src-tauri/src/db/postgres.rsindex 3ba3f84704..6dcef76cd6 100644--- a/src-tauri/src/db/postgres.rs+++ b/src-tauri/src/db/postgres.rs@@ -275,7 +275,7 @@ pub async fn execute_query(pool: &PgPool, sql: &str) -> Result<QueryResult, Stripub async fn list_indexes(pool: &PgPool, schema: &str, table: &str) -> Result<Vec<IndexInfo>, String> {let rows: Vec<PgRow> = sqlx::query("SELECT i.relname AS index_name, \- array_agg(COALESCE(a.attname, pg_get_indexdef(ix.indexrelid, k.n, true)) ORDER BY k.n) AS columns, \+ array_agg(COALESCE(a.attname, pg_get_indexdef(ix.indexrelid, k.n::int, true)) ORDER BY k.n) AS columns, \ix.indisunique AS is_unique, \ix.indisprimary AS is_primary, \pg_get_expr(ix.indpred, ix.indrelid) AS filter_expr, \diff --git a/src-tauri/src/db/sqlserver.rs b/src-tauri/src/db/sqlserver.rsindex 327c30eece..47d54c0bfe 100644--- a/src-tauri/src/db/sqlserver.rs+++ b/src-tauri/src/db/sqlserver.rs@@ -175,7 +175,7 @@ pub async fn list_indexes(client: &mut SqlServerClient, schema: &str, table: &stlet inc_str = row.get::<&str, _>(5).unwrap_or("");IndexInfo {name: row.get::<&str, _>(0).unwrap_or("").to_string(),- columns: cols_str.split(',').map(|s| s.to_string()).collect(),+ columns: cols_str.split(',').filter(|s| !s.is_empty()).map(|s| s.to_string()).collect(),is_unique: row.get::<bool, _>(2).unwrap_or(false),is_primary: row.get::<bool, _>(3).unwrap_or(false),filter: row.get::<&str, _>(6).map(|s| s.to_string()),diff --git a/src/components/structure/TableStructureEditorDialog.vue b/src/components/structure/TableStructureEditorDialog.vueindex ff1e5ff8f4..57ff3be89d 100644--- a/src/components/structure/TableStructureEditorDialog.vue+++ b/src/components/structure/TableStructureEditorDialog.vue@@ -16,6 +16,9 @@ import {import {DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";+import {+ Select, SelectContent, SelectItem, SelectTrigger, SelectValue,+} from "@/components/ui/select";import { useConnectionStore } from "@/stores/connectionStore";import { useToast } from "@/composables/useToast";import { buildTableStructureChangeSql, type EditableStructureColumn, type EditableStructureIndex } from "@/lib/tableStructureEditorSql";@@ -72,6 +75,26 @@ const connection = computed(() =>props.prefillConnectionId ? store.getConfig(props.prefillConnectionId) : undefined);const databaseType = computed(() => connection.value?.db_type);++const indexTypesByDb: Record<string, string[]> = {+ postgres: ["BTREE", "HASH", "GIST", "SPGIST", "GIN", "BRIN"],+ mysql: ["BTREE", "HASH", "FULLTEXT", "SPATIAL", "RTREE"],+ sqlserver: ["CLUSTERED", "NONCLUSTERED", "COLUMNSTORE", "NONCLUSTERED COLUMNSTORE", "XML", "SPATIAL"],+ oracle: ["NORMAL", "BITMAP", "FUNCTION-BASED NORMAL", "FUNCTION-BASED DOMAIN", "DOMAIN", "CLUSTER"],+ sqlite: ["BTREE"],+};+const indexTypeOptions = computed(() => indexTypesByDb[databaseType.value ?? ""] ?? []);++const indexColLabels = computed(() => [+ t('structureEditor.indexName'),+ t('structureEditor.indexColumns'),+ t('structureEditor.unique'),+ t('structureEditor.indexType'),+ t('structureEditor.includedColumns'),+ t('structureEditor.filter'),+ t('structureEditor.comment'),+ t('structureEditor.actions'),+]);const targetSchema = computed(() => props.prefillSchema || props.prefillDatabase || "");const targetLabel = computed(() => [connection.value?.name,@@ -341,23 +364,14 @@ watch(open, (value) => {<thead class="sticky top-0 z-10 bg-background"><tr><th- v-for="(label, i) in [- t('structureEditor.indexName'),- t('structureEditor.indexColumns'),- t('structureEditor.unique'),- t('structureEditor.indexType'),- t('structureEditor.includedColumns'),- t('structureEditor.filter'),- t('structureEditor.comment'),- t('structureEditor.actions'),- ]"+ v-for="(label, i) in indexColLabels":key="i"class="relative border-b border-r px-2 py-2 text-left":style="{ width: indexColWidths[i] + 'px', minWidth: indexColWidths[i] + 'px' }">{{ label }}<div- v-if="i < 7"+ v-if="i < indexColLabels.length - 1"class="absolute right-0 top-0 z-20 h-full w-1 cursor-col-resize hover:bg-primary/30":class="resizing?.col === i ? 'bg-primary/30' : ''"@mousedown="onIndexColResize($event, i)"@@ -404,6 +418,19 @@ watch(open, (value) => {</td><td class="border-b border-r px-2 py-1.5"><span v-if="index.original" class="text-muted-foreground">{{ index.indexType || 'BTREE' }}</span>+ <Select+ v-else-if="indexTypeOptions.length > 0"+ :model-value="index.indexType || 'BTREE'"+ :disabled="index.markedForDrop"+ @update:model-value="(v: string) => index.indexType = v"+ >+ <SelectTrigger class="h-7 font-mono text-xs">+ <SelectValue />+ </SelectTrigger>+ <SelectContent>+ <SelectItem v-for="opt in indexTypeOptions" :key="opt" :value="opt">{{ opt }}</SelectItem>+ </SelectContent>+ </Select><Inputv-elsev-model="index.indexType"diff --git a/src/lib/schemaDiff.ts b/src/lib/schemaDiff.tsindex d8f9137311..1be240f535 100644--- a/src/lib/schemaDiff.ts+++ b/src/lib/schemaDiff.ts@@ -184,8 +184,9 @@ export function generateSyncSql(const usingClause = idxType && dbType === "postgres" ? ` USING ${idxType}` : "";const typePrefix = idxType && dbType === "sqlserver" ? `${idxType} ` : "";const incCols = idx.source.included_columns ?? [];- const includeClause = incCols.length > 0 ? ` INCLUDE (${incCols.map((c) => quoteId(c, dbType)).join(", ")})` : "";- const filter = idx.source.filter ? ` WHERE ${idx.source.filter}` : "";+ const includeClause = incCols.length > 0 && (dbType === "postgres" || dbType === "sqlserver") ? ` INCLUDE (${incCols.map((c) => quoteId(c, dbType)).join(", ")})` : "";+ const supportsWhere = dbType === "postgres" || dbType === "sqlserver" || dbType === "sqlite";+ const filter = idx.source.filter && supportsWhere ? ` WHERE ${idx.source.filter}` : "";lines.push(`CREATE ${unique}${typePrefix}INDEX ${quoteId(idx.name, dbType)} ON ${qt}${usingClause} (${cols})${includeClause}${filter};`);} else if (idx.type === "removed") {if (isMySQL) {diff --git a/src/lib/tableStructureEditorSql.ts b/src/lib/tableStructureEditorSql.tsindex 4009e39f34..92923720e4 100644--- a/src/lib/tableStructureEditorSql.ts+++ b/src/lib/tableStructureEditorSql.ts@@ -253,9 +253,10 @@ function buildIndexSql(options: BuildTableStructureChangeSqlOptions, warnings: sconst usingClause = idxType && databaseType === "postgres" ? ` USING ${idxType}` : "";const typePrefix = idxType && databaseType === "sqlserver" ? `${idxType} ` : "";const incCols = index.includedColumns.map(clean).filter(Boolean);- const includeClause = incCols.length > 0 ? ` INCLUDE (${incCols.map((c) => quoteIdent(databaseType, c)).join(", ")})` : "";+ const includeClause = incCols.length > 0 && (databaseType === "postgres" || databaseType === "sqlserver") ? ` INCLUDE (${incCols.map((c) => quoteIdent(databaseType, c)).join(", ")})` : "";const filter = clean(index.filter);- const whereClause = filter ? ` WHERE ${filter}` : "";+ const supportsWhere = databaseType === "postgres" || databaseType === "sqlserver" || databaseType === "sqlite";+ const whereClause = filter && supportsWhere ? ` WHERE ${filter}` : "";statements.push(`CREATE ${unique}${typePrefix}INDEX ${quoteIdent(databaseType, name)} ON ${table}${usingClause} (${cols})${includeClause}${whereClause};`);const comment = clean(index.comment);if (comment && databaseType === "postgres") {diff --git a/tests/tableStructureEditorSql.test.ts b/tests/tableStructureEditorSql.test.tsindex a7c73ef686..7788e6f5f2 100644--- a/tests/tableStructureEditorSql.test.ts+++ b/tests/tableStructureEditorSql.test.ts@@ -392,7 +392,7 @@ test("SQL Server index with type + include combined", () => {]);});-test("MySQL index does not emit USING or type prefix, but INCLUDE and WHERE are passed through", () => {+test("MySQL index omits USING, type prefix, INCLUDE, and WHERE (unsupported)", () => {const result = buildTableStructureChangeSql({databaseType: "mysql",tableName: "orders",@@ -412,7 +412,7 @@ test("MySQL index does not emit USING or type prefix, but INCLUDE and WHERE areassert.deepEqual(result.warnings, []);assert.deepEqual(result.statements, [- "CREATE INDEX `idx_orders_status` ON `orders` (`status`) INCLUDE (`total`) WHERE deleted = 0;",+ "CREATE INDEX `idx_orders_status` ON `orders` (`status`);",]);});