fix(sqlserver): support primary key edits in structure editor

This commit is contained in:
YingNing authored and GitHub committed 2026-09-30 20:24:01 +08:00
1 parent c9e8ee53f7
commit a55466f578
6 files changed
+121 -23

No files matched your search

@@ -604,6 +604,26 @@ describe("TableStructureEditor primary key editing", () => {
);
});
it("allows an existing SQL Server primary key to be cleared", async () => {
const root = await mountEditor("sqlserver", true);
const primaryKey = columnCheckbox(root, "structureEditor.primaryKey");
expect(primaryKey.disabled).toBe(false);
expect(primaryKey.checked).toBe(true);
primaryKey.checked = false;
primaryKey.dispatchEvent(new Event("change", { bubbles: true }));
await nextTick();
expect(primaryKey.checked).toBe(false);
await vi.waitFor(() => expect(mocks.buildTableStructureChangeSql).toHaveBeenCalled());
expect(mocks.buildTableStructureChangeSql).toHaveBeenLastCalledWith(
expect.objectContaining({
columns: [expect.objectContaining({ isPrimaryKey: false })],
}),
);
});
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");
@@ -102,6 +102,10 @@ describe("tableStructureCapabilities", () => {
addPrimaryKey: true,
alterPrimaryKey: false,
});
expect(getTableStructureCapabilities("sqlserver", "sqlserver")).toMatchObject({
addPrimaryKey: true,
alterPrimaryKey: true,
});
for (const databaseType of ["oceanbase-oracle", "iris"] as const) {
expect(getTableStructureCapabilities(databaseType, databaseType)).toMatchObject({
addPrimaryKey: false,
@@ -186,6 +186,9 @@ const sqlserverCapabilities = capabilities({
indexInclude: true,
indexFilter: true,
indexComment: true,
// T-SQL: ALTER TABLE ... DROP CONSTRAINT <name> / ADD [CONSTRAINT name] PRIMARY KEY (...);
// the backend drops the persisted constraint by its index-metadata name (issue #10758).
alterPrimaryKey: true,
});
const oracleCompatibleCapabilities = capabilities({