fix(structure): improve mysql auto-increment editing and field shortcuts

This commit is contained in:
zipg authored and GitHub committed 2026-08-27 18:21:52 +08:00
1 parent 214bf86a6f
commit 4fed29fba2
17 files changed
+285 -78

No files matched your search

@@ -37,9 +37,10 @@ describe("MySQL table AUTO_INCREMENT counter", () => {
});
});
it("is editable only for existing native-MySQL tables with an active existing auto-increment column", () => {
it("is editable only for existing native-MySQL tables with an active auto-increment column draft", () => {
const nativeMysql = { db_type: "mysql", driver_profile: "mysql" } as any;
expect(canEditMysqlAutoIncrementCounter(nativeMysql, false, [existingColumn(true)])).toBe(true);
expect(canEditMysqlAutoIncrementCounter(nativeMysql, false, [{ ...existingColumn(true), original: undefined }])).toBe(true);
expect(canEditMysqlAutoIncrementCounter(nativeMysql, true, [existingColumn(true)])).toBe(false);
expect(canEditMysqlAutoIncrementCounter(nativeMysql, false, [existingColumn(false)])).toBe(false);
expect(canEditMysqlAutoIncrementCounter(nativeMysql, false, [{ ...existingColumn(true), markedForDrop: true }])).toBe(false);
@@ -0,0 +1,21 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { getMysqlTableAutoIncrement } from "@/lib/backend/http";
describe("MySQL AUTO_INCREMENT web API", () => {
afterEach(() => {
vi.unstubAllGlobals();
});
it("loads the table counter from the schema endpoint", async () => {
const fetchMock = vi.fn().mockResolvedValue({
ok: true,
status: 200,
json: vi.fn().mockResolvedValue("42"),
});
vi.stubGlobal("fetch", fetchMock);
await expect(getMysqlTableAutoIncrement("connection 1", "sales/db", "order items")).resolves.toBe("42");
expect(fetchMock).toHaveBeenCalledWith("/api/schema/mysql/auto-increment?connection_id=connection+1&database=sales%2Fdb&table=order+items");
});
});
+2 -2
View File
@@ -847,8 +847,8 @@ export async function getTableComment(_connectionId: string, _database: string,
throw new Error("Table comment lookup is not available in the web backend");
}
export async function getMysqlTableAutoIncrement(_connectionId: string, _database: string, _table: string): Promise<string | null> {
throw new Error("MySQL AUTO_INCREMENT metadata is not available in the web backend");
export async function getMysqlTableAutoIncrement(connectionId: string, database: string, table: string): Promise<string | null> {
return get(`/api/schema/mysql/auto-increment?${qs({ connection_id: connectionId, database, table })}`);
}
export async function listObjects(connectionId: string, database: string, schema: string, objectTypes?: (SidebarObjectKind | "EVENT")[], filter?: string, limit?: number, offset?: number, catalog?: string, tableNameFilter?: TableNameFilter): Promise<ObjectInfo[]> {
@@ -20,7 +20,7 @@ export function refreshMysqlAutoIncrementCounterDraft(serverValue: string | null
export function canEditMysqlAutoIncrementCounter(connection: Pick<ConnectionConfig, "db_type" | "driver_profile"> | undefined, isCreateMode: boolean, columns: readonly EditableStructureColumn[]): boolean {
if (isCreateMode || !supportsNativeMysqlAutoIncrement(connection)) return false;
return columns.some((column) => !!column.original && !column.markedForDrop && column.extra.autoIncrement === true);
return columns.some((column) => !column.markedForDrop && column.extra.autoIncrement === true);
}
export interface BuildMysqlAutoIncrementCounterStatementOptions extends Omit<MysqlAutoIncrementSqlOptions, "databaseType" | "value"> {