1 parent
278429ab07
commit
4c6c3142c0
18 files changed
+456
-7
No files matched your search
+40
-1
@@ -8,16 +8,55 @@ const apiMock = vi.hoisted(() => ({
|
||||
listTriggers: vi.fn(),
|
||||
buildCreateTableSql: vi.fn(),
|
||||
buildDuplicateTableStructureSql: vi.fn(),
|
||||
buildMysqlAutoIncrementSql: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("@/lib/backend/api", () => apiMock);
|
||||
|
||||
import { buildDuplicateTableStructurePlan, collectDuplicateTableColumnComments, damengDropSchemaExecutionSchema, damengDuplicateTableCreateOptions, duplicateTableStructureRequiresScript, oracleDuplicateTableCreateOptions } from "@/lib/database/dbAdminSql";
|
||||
import { buildDuplicateTableStructurePlan, buildMysqlAutoIncrementSql, collectDuplicateTableColumnComments, damengDropSchemaExecutionSchema, damengDuplicateTableCreateOptions, duplicateTableStructureRequiresScript, oracleDuplicateTableCreateOptions, supportsNativeMysqlAutoIncrement } from "@/lib/database/dbAdminSql";
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("MySQL AUTO_INCREMENT administration", () => {
|
||||
it("is available only for explicit native MySQL connections", () => {
|
||||
expect(supportsNativeMysqlAutoIncrement({ db_type: "mysql", driver_profile: undefined })).toBe(true);
|
||||
expect(supportsNativeMysqlAutoIncrement({ db_type: "mysql", driver_profile: "" })).toBe(true);
|
||||
expect(supportsNativeMysqlAutoIncrement({ db_type: "mysql", driver_profile: " MySQL " })).toBe(true);
|
||||
|
||||
for (const connection of [
|
||||
{ db_type: "jdbc", driver_profile: "mysql" },
|
||||
{ db_type: "mysql", driver_profile: "mariadb" },
|
||||
{ db_type: "mysql", driver_profile: "tidb" },
|
||||
{ db_type: "mysql", driver_profile: "oceanbase" },
|
||||
{ db_type: "mysql", driver_profile: "dolt" },
|
||||
{ db_type: "goldendb", driver_profile: "goldendb" },
|
||||
{ db_type: "mysql", driver_profile: "goldendb" },
|
||||
{ db_type: "doris", driver_profile: "doris" },
|
||||
{ db_type: "doris", driver_profile: "selectdb" },
|
||||
{ db_type: "starrocks", driver_profile: "starrocks" },
|
||||
] as const) {
|
||||
expect(supportsNativeMysqlAutoIncrement(connection as any)).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the counter as a decimal string across the frontend boundary", async () => {
|
||||
apiMock.buildMysqlAutoIncrementSql.mockResolvedValue("ALTER TABLE `sales`.`events` AUTO_INCREMENT = 18446744073709551615;");
|
||||
|
||||
await expect(
|
||||
buildMysqlAutoIncrementSql({
|
||||
databaseType: "mysql",
|
||||
driverProfile: "mysql",
|
||||
schema: "sales",
|
||||
tableName: "events",
|
||||
value: "18446744073709551615",
|
||||
}),
|
||||
).resolves.toContain("18446744073709551615");
|
||||
expect(apiMock.buildMysqlAutoIncrementSql).toHaveBeenCalledWith(expect.objectContaining({ value: "18446744073709551615" }));
|
||||
});
|
||||
});
|
||||
|
||||
describe("collectDuplicateTableColumnComments", () => {
|
||||
it("preserves meaningful whitespace and excludes whitespace-only comments", () => {
|
||||
expect(
|
||||
|
||||
@@ -223,6 +223,7 @@ export const buildDropTableSql = forward("buildDropTableSql");
|
||||
export const buildDropTableChildObjectSql = forward("buildDropTableChildObjectSql");
|
||||
export const buildEmptyTableSql = forward("buildEmptyTableSql");
|
||||
export const buildTruncateTableSql = forward("buildTruncateTableSql");
|
||||
export const buildMysqlAutoIncrementSql = forward("buildMysqlAutoIncrementSql");
|
||||
export const buildDropDatabaseSql = forward("buildDropDatabaseSql");
|
||||
export const buildCreateSchemaSql = forward("buildCreateSchemaSql");
|
||||
export const buildUpdateDatabasePropertiesSql = forward("buildUpdateDatabasePropertiesSql");
|
||||
|
||||
@@ -159,7 +159,7 @@ import type { BuildEditableObjectSourceSqlInput, BuildRoutineRenameObjectSourceI
|
||||
import type { BuildViewDdlInput } from "@/lib/table/viewDdl";
|
||||
import type { BuildRenameObjectSqlOptions } from "@/lib/table/objectRenameSql";
|
||||
import type { CreateDatabaseSqlOptions } from "@/lib/database/createDatabaseSql";
|
||||
import type { DatabaseNameSqlOptions, DatabasePropertyEditSqlOptions, DropTableChildObjectSqlOptions, DropObjectSqlOptions, DuplicateTableStructureSqlOptions, CopyTableDataSqlOptions, SchemaNameSqlOptions, TableAdminSqlOptions } from "@/lib/database/dbAdminSql";
|
||||
import type { DatabaseNameSqlOptions, DatabasePropertyEditSqlOptions, DropTableChildObjectSqlOptions, DropObjectSqlOptions, DuplicateTableStructureSqlOptions, CopyTableDataSqlOptions, MysqlAutoIncrementSqlOptions, SchemaNameSqlOptions, TableAdminSqlOptions } from "@/lib/database/dbAdminSql";
|
||||
import type { BuildDatabaseSqlExportOptions, BuildExportInsertStatementsOptions } from "@/lib/export/databaseExport";
|
||||
import { loadBrowserAppState, saveBrowserAppState } from "@/lib/backend/browserAppStateStorage";
|
||||
import type { DataCompareFromTablesOptions, DataCompareFromTablesPreparation, DataCompareSyncPlan, DataCompareSyncPlanOptions, DataComparePreparation, DataComparePreparationOptions } from "@/lib/dataGrid/dataCompare";
|
||||
@@ -1238,6 +1238,10 @@ export async function buildTruncateTableSql(options: TableAdminSqlOptions): Prom
|
||||
return post("/api/query/build-truncate-table-sql", { options });
|
||||
}
|
||||
|
||||
export async function buildMysqlAutoIncrementSql(options: MysqlAutoIncrementSqlOptions): Promise<string> {
|
||||
return post("/api/query/build-mysql-auto-increment-sql", { options });
|
||||
}
|
||||
|
||||
export async function buildDropDatabaseSql(options: DatabaseNameSqlOptions): Promise<string> {
|
||||
return post("/api/query/build-drop-database-sql", { options });
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ import type { BuildEditableObjectSourceSqlInput, BuildRoutineRenameObjectSourceI
|
||||
import type { BuildViewDdlInput } from "@/lib/table/viewDdl";
|
||||
import type { BuildRenameObjectSqlOptions } from "@/lib/table/objectRenameSql";
|
||||
import type { CreateDatabaseSqlOptions } from "@/lib/database/createDatabaseSql";
|
||||
import type { DatabaseNameSqlOptions, DatabasePropertyEditSqlOptions, DropTableChildObjectSqlOptions, DropObjectSqlOptions, DuplicateTableStructureSqlOptions, CopyTableDataSqlOptions, SchemaNameSqlOptions, TableAdminSqlOptions } from "@/lib/database/dbAdminSql";
|
||||
import type { DatabaseNameSqlOptions, DatabasePropertyEditSqlOptions, DropTableChildObjectSqlOptions, DropObjectSqlOptions, DuplicateTableStructureSqlOptions, CopyTableDataSqlOptions, MysqlAutoIncrementSqlOptions, SchemaNameSqlOptions, TableAdminSqlOptions } from "@/lib/database/dbAdminSql";
|
||||
import type { BuildDatabaseSqlExportOptions, BuildExportInsertStatementsOptions } from "@/lib/export/databaseExport";
|
||||
|
||||
export interface SshPromptResolution {
|
||||
@@ -1418,6 +1418,10 @@ export async function buildTruncateTableSql(options: TableAdminSqlOptions): Prom
|
||||
return invoke("build_truncate_table_sql", { options });
|
||||
}
|
||||
|
||||
export async function buildMysqlAutoIncrementSql(options: MysqlAutoIncrementSqlOptions): Promise<string> {
|
||||
return invoke("build_mysql_auto_increment_sql", { options });
|
||||
}
|
||||
|
||||
export async function buildDropDatabaseSql(options: DatabaseNameSqlOptions): Promise<string> {
|
||||
return invoke("build_drop_database_sql", { options });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ColumnInfo, DatabaseObjectType, DatabaseType, ForeignKeyInfo, IndexInfo, TriggerInfo } from "@/types/database";
|
||||
import type { ColumnInfo, ConnectionConfig, DatabaseObjectType, DatabaseType, ForeignKeyInfo, IndexInfo, TriggerInfo } from "@/types/database";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { createColumnDrafts, createForeignKeyDrafts, createIndexDrafts, createTriggerDrafts } from "@/lib/table/tableStructureEditorState";
|
||||
import type { BuildTableStructureChangeSqlOptions } from "@/lib/table/tableStructureEditorSql";
|
||||
@@ -18,6 +18,14 @@ export interface TableAdminSqlOptions {
|
||||
cascade?: boolean;
|
||||
}
|
||||
|
||||
export interface MysqlAutoIncrementSqlOptions {
|
||||
databaseType: DatabaseType;
|
||||
driverProfile?: string | null;
|
||||
schema?: string | null;
|
||||
tableName: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type TableChildObjectType = "COLUMN" | "INDEX" | "FOREIGN_KEY" | "TRIGGER";
|
||||
|
||||
export interface DropTableChildObjectSqlOptions {
|
||||
@@ -278,6 +286,16 @@ export function buildTruncateTableSql(options: TableAdminSqlOptions): Promise<st
|
||||
return api.buildTruncateTableSql(options);
|
||||
}
|
||||
|
||||
export function buildMysqlAutoIncrementSql(options: MysqlAutoIncrementSqlOptions): Promise<string> {
|
||||
return api.buildMysqlAutoIncrementSql(options);
|
||||
}
|
||||
|
||||
export function supportsNativeMysqlAutoIncrement(connection: Pick<ConnectionConfig, "db_type" | "driver_profile"> | undefined): boolean {
|
||||
if (connection?.db_type !== "mysql") return false;
|
||||
const profile = connection.driver_profile?.trim().toLowerCase();
|
||||
return !profile || profile === "mysql";
|
||||
}
|
||||
|
||||
const DROP_TABLE_CASCADE_DATABASE_TYPES: readonly DatabaseType[] = ["postgres", "redshift", "gaussdb", "kwdb", "kingbase", "highgo", "uxdb", "vastbase", "opengauss"];
|
||||
const TRUNCATE_TABLE_CASCADE_DATABASE_TYPES: readonly DatabaseType[] = ["postgres", "gaussdb", "kwdb", "kingbase", "highgo", "uxdb", "vastbase", "opengauss"];
|
||||
|
||||
|
||||
@@ -12,6 +12,14 @@ export interface SidebarDangerDialogProgress {
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface SidebarDangerDialogTextInput {
|
||||
value: string;
|
||||
label: string;
|
||||
placeholder?: string;
|
||||
inputMode?: "text" | "numeric";
|
||||
onInput?: (value: string) => void | Promise<void>;
|
||||
}
|
||||
|
||||
export interface SidebarDangerDialogRequest {
|
||||
target: SidebarActionTarget;
|
||||
title: string;
|
||||
@@ -24,5 +32,6 @@ export interface SidebarDangerDialogRequest {
|
||||
closeOnConfirm?: boolean;
|
||||
progress?: SidebarDangerDialogProgress;
|
||||
option?: SidebarDangerDialogOption;
|
||||
textInput?: SidebarDangerDialogTextInput;
|
||||
confirm: () => void | Promise<void>;
|
||||
}
|
||||
Reference in new issue
Block a user