fix(structure): respect identifier quote preference

This commit is contained in:
Eve authored and GitHub committed 2026-09-10 13:14:19 +08:00
1 parent dd708fc052
commit e17246c0f6
10 files changed
+77 -13

No files matched your search

@@ -76,6 +76,27 @@ describe("concurrentIndexNamesInStatements", () => {
expect(concurrentIndexNamesInStatements([])).toEqual([]);
expect(concurrentIndexNamesInStatements(['CREATE INDEX "idx" ON "public"."t" ("c");'])).toEqual([]);
});
it("extracts names from dequoted statements when the identifier-quote preference is off", () => {
expect(
concurrentIndexNamesInStatements([
"CREATE INDEX CONCURRENTLY idx_users_email ON public.users (email);",
"CREATE UNIQUE INDEX CONCURRENTLY uniq_users_name ON public.users (name);",
'CREATE INDEX CONCURRENTLY "MixedCase".idx_orders_id ON orders.orders (id);',
"CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_ifne ON public.users (id);",
]),
).toEqual(["idx_users_email", "uniq_users_name", "idx_orders_id", "idx_ifne"]);
});
it("still detects a same-name INVALID index after dequoting (quote preference off)", () => {
// Regression for the pre-apply guard at TableStructureEditor applyChanges:
// with generateSqlQuoteIdentifiers disabled, pendingStatements are dequoted
// before the guard runs, so the extracted name must still match the
// listInvalidIndexes result and block the save.
const invalidIndexes = ["idx_users_email"];
const concurrentIndexNames = concurrentIndexNamesInStatements(["CREATE INDEX CONCURRENTLY idx_users_email ON public.users (email);"]);
expect(concurrentIndexNames.filter((name) => invalidIndexes.includes(name))).toEqual(["idx_users_email"]);
});
});
describe("normalizeUnsupportedConcurrentIndexes", () => {
@@ -227,7 +227,7 @@ vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ tableStructureRe
vi.mock("@/stores/historyStore", () => ({ useHistoryStore: () => ({ add: vi.fn() }) }));
vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [] },
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], generateSqlQuoteIdentifiers: true },
updateEditorSettings: mocks.updateEditorSettings,
}),
}));
@@ -19,6 +19,7 @@ vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({
editorSettings: {
regexMaxMatchCount: 1000,
generateSqlQuoteIdentifiers: true,
},
}),
}));
@@ -259,7 +259,7 @@ vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ tableStructureRe
vi.mock("@/stores/historyStore", () => ({ useHistoryStore: () => ({ add: vi.fn() }) }));
vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], fontSize: 13, fontFamily: "monospace", theme: "default" },
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], fontSize: 13, fontFamily: "monospace", theme: "default", generateSqlQuoteIdentifiers: true },
updateEditorSettings: mocks.updateEditorSettings,
}),
}));
@@ -176,7 +176,7 @@ vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ tableStructureRe
vi.mock("@/stores/historyStore", () => ({ useHistoryStore: () => ({ add: vi.fn() }) }));
vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], theme: "default", fontSize: 13, fontFamily: "monospace" },
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], theme: "default", fontSize: 13, fontFamily: "monospace", generateSqlQuoteIdentifiers: true },
updateEditorSettings: vi.fn(),
}),
}));
@@ -259,7 +259,7 @@ vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ tableStructureRe
vi.mock("@/stores/historyStore", () => ({ useHistoryStore: () => ({ add: vi.fn() }) }));
vi.mock("@/stores/settingsStore", () => ({
useSettingsStore: () => ({
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], fontSize: 13, fontFamily: "monospace", theme: "default" },
editorSettings: { structureEditorDensity: "compact", sqlFormatter: {}, tableColumnTemplateFields: [], fontSize: 13, fontFamily: "monospace", theme: "default", generateSqlQuoteIdentifiers: true },
updateEditorSettings: mocks.updateEditorSettings,
}),
}));