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(safety): guard object browser batch empty
wuxiemian130477c48c13
diff --git a/apps/desktop/src/components/objects/ObjectBrowser.vue b/apps/desktop/src/components/objects/ObjectBrowser.vueindex e9d225e96a..1d5d1e0d54 100644--- a/apps/desktop/src/components/objects/ObjectBrowser.vue+++ b/apps/desktop/src/components/objects/ObjectBrowser.vue@@ -1534,9 +1534,13 @@ async function confirmBatchEmptyTables() {const plan = batchEmptyPlan.value.slice();if (plan.length === 0) return;const asynchronousMutation = effectiveDatabaseType.value === "clickhouse";- const result = await runBatchTableEmpty(plan, async ({ sql }) => {- await api.executeQuery(props.connection.id, props.database, sql);+ const reviewSql = plan.map(({ sql }) => sql).join(";\n");+ const result = await executeObjectBrowserSqlWithProductionGuard(reviewSql, () => {+ return runBatchTableEmpty(plan, async ({ sql }) => {+ await api.executeQuery(props.connection.id, props.database, sql);+ });});+ if (!result) return;for (const failure of result.failed) {console.error(`Failed to empty table "${failure.target.target.name}":`, failure.error);}diff --git a/packages/app-tests/productionGuardEntrypoints.test.ts b/packages/app-tests/productionGuardEntrypoints.test.tsindex 5e4a94f1e9..ce61514c49 100644--- a/packages/app-tests/productionGuardEntrypoints.test.ts+++ b/packages/app-tests/productionGuardEntrypoints.test.ts@@ -6,6 +6,26 @@ function readSource(path: string): string {return readFileSync(path, "utf8");}+function functionBody(source: string, name: string): string {+ const signature = `function ${name}(`;+ const asyncSignature = `async ${signature}`;+ const signatureIndex = source.indexOf(asyncSignature) >= 0 ? source.indexOf(asyncSignature) : source.indexOf(signature);+ assert.notEqual(signatureIndex, -1, `Could not find function ${name}`);+ const bodyStart = source.indexOf("{", signatureIndex);+ assert.notEqual(bodyStart, -1, `Could not find body for ${name}`);++ let depth = 0;+ for (let index = bodyStart; index < source.length; index += 1) {+ const char = source[index];+ if (char === "{") depth += 1;+ if (char === "}") {+ depth -= 1;+ if (depth === 0) return source.slice(bodyStart + 1, index);+ }+ }+ throw new Error(`Could not parse body for ${name}`);+}+test("secondary write entrypoints use the shared production SQL guard", () => {const entrypoints = [{@@ -77,3 +97,11 @@ test("secondary write entrypoints use the shared production SQL guard", () => {assert.ok(source.includes(entrypoint.sourceKey), `${entrypoint.path} should label the confirmation source`);}});++test("object browser batch empty reviews the frozen SQL plan before executing", () => {+ const source = readSource("apps/desktop/src/components/objects/ObjectBrowser.vue");+ const body = functionBody(source, "confirmBatchEmptyTables");+ assert.match(body, /executeObjectBrowserSqlWithProductionGuard\(\s*reviewSql/, "batch empty must use the Object Browser production guard");+ assert.match(body, /runBatchTableEmpty/, "batch empty should still use the batch executor after confirmation");+ assert.ok(body.indexOf("executeObjectBrowserSqlWithProductionGuard") < body.indexOf("runBatchTableEmpty"), "production guard must be entered before the batch executor");+});