Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(schema): keep create-table SQL preview visible

zipgca303e555379
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.primaryKey.spec.ts b/apps/desktop/src/components/structure/TableStructureEditor.primaryKey.spec.ts
index 20a8564437..2d6b1dcddb 100644
--- a/apps/desktop/src/components/structure/TableStructureEditor.primaryKey.spec.ts
+++ b/apps/desktop/src/components/structure/TableStructureEditor.primaryKey.spec.ts
@@ -362,6 +362,36 @@ describe("TableStructureEditor primary key editing", () => {
}),
);
});
+
+ it("keeps the current SQL preview visible while a newer preview is loading", async () => {
+ const root = await mountEditor("dameng", true);
+ const primaryKey = columnCheckbox(root, "structureEditor.primaryKey");
+ const nullable = columnCheckbox(root, "structureEditor.nullable");
+ const firstSql = "ALTER TABLE users DROP CONSTRAINT users_pkey;";
+
+ mocks.buildTableStructureChangeSql.mockResolvedValueOnce({ statements: [firstSql], warnings: [] });
+ primaryKey.checked = false;
+ primaryKey.dispatchEvent(new Event("change", { bubbles: true }));
+
+ await vi.waitFor(() => expect(root.textContent).toContain(firstSql));
+
+ let resolveLatestPreview!: (value: { statements: string[]; warnings: string[] }) => void;
+ mocks.buildTableStructureChangeSql.mockImplementationOnce(
+ () =>
+ new Promise((resolve) => {
+ resolveLatestPreview = resolve;
+ }),
+ );
+ nullable.checked = true;
+ nullable.dispatchEvent(new Event("change", { bubbles: true }));
+
+ await vi.waitFor(() => expect(mocks.buildTableStructureChangeSql).toHaveBeenCalledTimes(2));
+ expect(root.textContent).toContain(firstSql);
+ expect(root.textContent).not.toContain("structureEditor.noChanges");
+
+ resolveLatestPreview({ statements: ["ALTER TABLE users ALTER COLUMN id DROP NOT NULL;"], warnings: [] });
+ await vi.waitFor(() => expect(root.textContent).toContain("ALTER TABLE users ALTER COLUMN id DROP NOT NULL;"));
+ });
});
describe("TableStructureEditor local column order notice", () => {
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vue
index af9be48111..d4df49db3b 100644
--- a/apps/desktop/src/components/structure/TableStructureEditor.vue
+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue
@@ -1119,10 +1119,10 @@ function scheduleSqlPreviewRefresh() {
}
sqlPreviewRequestId++;
deferredSqlPreviewRefresh = false;
- pendingStatements.value = [];
- warnings.value = [];
- sqliteSchemaRevision.value = undefined;
if (!hasPendingStructureChanges()) {
+ pendingStatements.value = [];
+ warnings.value = [];
+ sqliteSchemaRevision.value = undefined;
sqlPreviewLoading.value = false;
return;
}