1 parent
4329ec51db
commit
20c50550cf
13 files changed
+380
-13
No files matched your search
@@ -121,7 +121,7 @@ watch([sourceDbType, targetDbType], ([src, tgt]) => {
|
||||
});
|
||||
const optionTree = computed(() => {
|
||||
const targetConfig = store.getConfig(targetConnectionId.value);
|
||||
const dbType = targetConfig?.db_type || "postgres";
|
||||
const dbType = schemaDiffEngineDatabaseType(targetConfig) || targetConfig?.db_type || "postgres";
|
||||
return getSchemaDiffOptionsForDbType(dbType);
|
||||
});
|
||||
|
||||
|
||||
@@ -58,6 +58,15 @@ describe("SchemaDiffOptionsPanel", () => {
|
||||
expect(normalized.ignoreColumnNameCase).toBe(false);
|
||||
});
|
||||
|
||||
it("exposes charset comparison only for supported MySQL targets and defaults it on", () => {
|
||||
expect(getSchemaDiffOptionsForDbType("mysql").map((item) => item.id)).toContain("compareCharset");
|
||||
expect(getSchemaDiffOptionsForDbType("goldendb").map((item) => item.id)).toContain("compareCharset");
|
||||
expect(getSchemaDiffOptionsForDbType("starrocks").map((item) => item.id)).not.toContain("compareCharset");
|
||||
expect(getSchemaDiffOptionsForDbType("doris").map((item) => item.id)).not.toContain("compareCharset");
|
||||
expect(getSchemaDiffOptionsForDbType("postgres").map((item) => item.id)).not.toContain("compareCharset");
|
||||
expect(normalizeSchemaDiffCompareOptions({}, "mysql").compareCharset).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps unsaved checkbox edits when the parent refreshes equivalent options", async () => {
|
||||
const options = ref<SchemaDiffCompareOptions>({ ...DEFAULT_POSTGRES_OPTIONS });
|
||||
const optionTree: SchemaDiffOptionItem[] = [{ id: "views", labelKey: "views", defaultChecked: true }];
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const CONFIG_KEY = "dbx-schema-diff-configs";
|
||||
const HISTORY_KEY = "dbx-schema-diff-history";
|
||||
|
||||
function storedConfig(compareCharset?: boolean) {
|
||||
return {
|
||||
id: "saved",
|
||||
name: "Saved",
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
sourceConnectionId: "source",
|
||||
sourceDatabase: "app",
|
||||
sourceSchema: "",
|
||||
targetConnectionId: "target",
|
||||
targetDatabase: "app_copy",
|
||||
targetSchema: "",
|
||||
options: {
|
||||
tables: true,
|
||||
...(compareCharset === undefined ? {} : { compareCharset }),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("schema diff charset option persistence", () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
it("migrates legacy saved configs and history entries to comparison enabled", async () => {
|
||||
localStorage.setItem(CONFIG_KEY, JSON.stringify([storedConfig()]));
|
||||
localStorage.setItem(HISTORY_KEY, JSON.stringify([storedConfig()]));
|
||||
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
|
||||
expect(state.configs.value[0].options.compareCharset).toBe(true);
|
||||
expect(state.recentConfigs.value[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(HISTORY_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves and persists an explicitly disabled value", async () => {
|
||||
localStorage.setItem(CONFIG_KEY, JSON.stringify([storedConfig(false)]));
|
||||
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
state.activeConfigId.value = "saved";
|
||||
|
||||
expect(state.activeConfig.value?.options.compareCharset).toBe(false);
|
||||
state.updateActiveConfigOptions({ ...state.activeConfig.value!.options, compareCharset: false });
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(false);
|
||||
});
|
||||
|
||||
it("migrates legacy imported configs before persisting them", async () => {
|
||||
const { useSchemaDiffConfig } = await import("../useSchemaDiffConfig");
|
||||
const state = useSchemaDiffConfig();
|
||||
|
||||
expect(state.importConfigs(JSON.stringify(storedConfig()), "replace")).toEqual({ imported: 1, renamed: 0 });
|
||||
expect(state.configs.value[0].options.compareCharset).toBe(true);
|
||||
expect(JSON.parse(localStorage.getItem(CONFIG_KEY) ?? "[]")[0].options.compareCharset).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,7 @@ async function waitForSession(session: { status: string }) {
|
||||
test("defaults enable tables and functions compare for common targets", () => {
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.tables, true);
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.functions, true);
|
||||
assert.equal(DEFAULT_MYSQL_OPTIONS.compareCharset, true);
|
||||
assert.equal(getDefaultOptionsForDbType("oracle").tables, true);
|
||||
assert.equal(getDefaultOptionsForDbType("oracle").functions, true);
|
||||
assert.equal(getDefaultOptionsForDbType("mysql").tables, true);
|
||||
@@ -82,12 +83,49 @@ test("runs a schema diff session after the dialog is closed and retains the prep
|
||||
assert.equal(trackerMock.updateCompareTask.mock.calls.at(-1)?.[1].status, "Done");
|
||||
// MySQL defaults now enable functions compare for same-dialect pairs.
|
||||
assert.equal(apiMock.listFunctions.mock.calls.length, 2);
|
||||
assert.equal(apiMock.prepareSchemaDiff.mock.calls[0]?.[0]?.compareCharset, true);
|
||||
|
||||
const onOpen = trackerMock.addSchemaDiffTask.mock.calls[0]?.[2] as (() => void) | undefined;
|
||||
onOpen?.();
|
||||
assert.equal(openMock.mock.calls.at(-1)?.[0], session.id);
|
||||
});
|
||||
|
||||
test("forwards a disabled charset comparison to the backend", async () => {
|
||||
apiMock.prepareSchemaDiff.mockClear();
|
||||
apiMock.prepareSchemaDiff.mockResolvedValue({
|
||||
diffs: [],
|
||||
functionDiffs: [],
|
||||
sequenceDiffs: [],
|
||||
ruleDiffs: [],
|
||||
ownerDiffs: [],
|
||||
renameCandidates: [],
|
||||
syncSql: "",
|
||||
rollbackSyncSql: "",
|
||||
});
|
||||
|
||||
const session = startSchemaDiffSession(
|
||||
{
|
||||
sourceConnectionId: "source",
|
||||
sourceDatabase: "app",
|
||||
sourceSchema: "",
|
||||
targetConnectionId: "target",
|
||||
targetDatabase: "warehouse",
|
||||
targetSchema: "",
|
||||
sourceDbType: "mysql",
|
||||
targetDbType: "mysql",
|
||||
options: { compareCharset: false },
|
||||
ignoreComments: false,
|
||||
label: "charset disabled",
|
||||
},
|
||||
{ tableListLoader: { load: vi.fn().mockResolvedValue([]) } },
|
||||
);
|
||||
|
||||
await waitForSession(session);
|
||||
|
||||
assert.equal(session.status, "completed");
|
||||
assert.equal(apiMock.prepareSchemaDiff.mock.calls[0]?.[0]?.compareCharset, false);
|
||||
});
|
||||
|
||||
test("loads routines for mysql↔mysql when functions is enabled", async () => {
|
||||
apiMock.prepareSchemaDiff.mockClear();
|
||||
apiMock.listFunctions.mockClear();
|
||||
|
||||
@@ -11,12 +11,29 @@ const configs = ref<SchemaDiffConfig[]>(loadConfigsFromStorage());
|
||||
const activeConfigId = ref<string>("");
|
||||
const recentConfigs = ref<SchemaDiffConfig[]>(loadHistoryFromStorage());
|
||||
|
||||
function migrateStoredConfig(config: SchemaDiffConfig): SchemaDiffConfig {
|
||||
return {
|
||||
...config,
|
||||
options: {
|
||||
...config.options,
|
||||
compareCharset: config.options?.compareCharset ?? true,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function parseStoredConfigs(raw: string | null, storageKey: string): SchemaDiffConfig[] {
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as SchemaDiffConfig[];
|
||||
if (!Array.isArray(parsed)) return [];
|
||||
const migrated = parsed.map(migrateStoredConfig);
|
||||
const serialized = JSON.stringify(migrated);
|
||||
if (serialized !== raw) localStorage.setItem(storageKey, serialized);
|
||||
return migrated;
|
||||
}
|
||||
|
||||
function loadConfigsFromStorage(): SchemaDiffConfig[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as SchemaDiffConfig[];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
return parseStoredConfigs(localStorage.getItem(STORAGE_KEY), STORAGE_KEY);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
@@ -24,10 +41,7 @@ function loadConfigsFromStorage(): SchemaDiffConfig[] {
|
||||
|
||||
function loadHistoryFromStorage(): SchemaDiffConfig[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(HISTORY_KEY);
|
||||
if (!raw) return [];
|
||||
const parsed = JSON.parse(raw) as SchemaDiffConfig[];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
return parseStoredConfigs(localStorage.getItem(HISTORY_KEY), HISTORY_KEY);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
@@ -136,7 +150,8 @@ export function useSchemaDiffConfig() {
|
||||
}
|
||||
|
||||
for (const item of items) {
|
||||
let name = item.name;
|
||||
const migrated = migrateStoredConfig(item);
|
||||
let name = migrated.name;
|
||||
if (configs.value.some((c) => c.name === name && c.id !== item.id)) {
|
||||
let counter = 1;
|
||||
let candidate = `${name} (${counter})`;
|
||||
@@ -149,7 +164,7 @@ export function useSchemaDiffConfig() {
|
||||
}
|
||||
const newId = uuid();
|
||||
configs.value.push({
|
||||
...item,
|
||||
...migrated,
|
||||
id: newId,
|
||||
name,
|
||||
createdAt: Date.now(),
|
||||
|
||||
@@ -226,6 +226,7 @@ async function runSchemaDiffSession(session: SchemaDiffSession, dependencies: Sc
|
||||
ignoreComments: input.ignoreComments,
|
||||
cascadeDelete: sessionOptions.cascadeDelete ?? false,
|
||||
compareColumnOrder: sessionOptions.compareColumnOrder,
|
||||
compareCharset: sessionOptions.compareCharset,
|
||||
ignoreTableNameCase: sessionOptions.ignoreTableNameCase,
|
||||
ignoreColumnNameCase: sessionOptions.ignoreColumnNameCase,
|
||||
detectRenames: sessionOptions.detectRenames ?? false,
|
||||
|
||||
@@ -7594,6 +7594,7 @@ export default {
|
||||
cascadeDelete: "Use CASCADE delete",
|
||||
sequenceLastValues: "Compare sequence last values",
|
||||
compareColumnOrder: "Compare column order",
|
||||
compareCharset: "Compare character sets and collations",
|
||||
ignoreTableNameCase: "Ignore table name case",
|
||||
ignoreColumnNameCase: "Ignore column name case",
|
||||
detectRenames: "Detect renames",
|
||||
|
||||
@@ -7560,6 +7560,7 @@ export default withEnglishFallback({
|
||||
cascadeDelete: "使用级联删除",
|
||||
sequenceLastValues: "比较序列最后值",
|
||||
compareColumnOrder: "比较字段顺序",
|
||||
compareCharset: "比较字符集和排序规则",
|
||||
ignoreTableNameCase: "忽略表名大小写",
|
||||
ignoreColumnNameCase: "忽略字段名大小写",
|
||||
detectRenames: "检测重命名",
|
||||
|
||||
@@ -242,6 +242,7 @@ export interface SchemaDiffPreparationOptions {
|
||||
ignoreComments?: boolean;
|
||||
cascadeDelete?: boolean;
|
||||
compareColumnOrder?: boolean;
|
||||
compareCharset?: boolean;
|
||||
ignoreTableNameCase?: boolean;
|
||||
ignoreColumnNameCase?: boolean;
|
||||
detectRenames?: boolean;
|
||||
|
||||
@@ -30,10 +30,13 @@ export const POSTGRES_SCHEMA_DIFF_OPTIONS: SchemaDiffOptionItem[] = [
|
||||
{ id: "enableRollback", labelKey: "schemaDiff.options.enableRollback", defaultChecked: false },
|
||||
];
|
||||
|
||||
export const MYSQL_SCHEMA_DIFF_OPTIONS: SchemaDiffOptionItem[] = [...POSTGRES_SCHEMA_DIFF_OPTIONS, { id: "compareCharset", labelKey: "schemaDiff.options.compareCharset", defaultChecked: true }];
|
||||
|
||||
export const SCHEMA_DIFF_OPTIONS_BY_DB_TYPE: Record<string, SchemaDiffOptionItem[]> = {
|
||||
postgres: POSTGRES_SCHEMA_DIFF_OPTIONS,
|
||||
opengauss: POSTGRES_SCHEMA_DIFF_OPTIONS,
|
||||
// mysql: [...] 后续扩展
|
||||
mysql: MYSQL_SCHEMA_DIFF_OPTIONS,
|
||||
goldendb: MYSQL_SCHEMA_DIFF_OPTIONS,
|
||||
// sqlserver: [...] 后续扩展
|
||||
};
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ export interface SchemaDiffCompareOptions {
|
||||
cascadeDelete: boolean;
|
||||
sequenceLastValues: boolean;
|
||||
compareColumnOrder: boolean;
|
||||
compareCharset: boolean;
|
||||
ignoreTableNameCase: boolean;
|
||||
ignoreColumnNameCase: boolean;
|
||||
tableIncludePattern: string;
|
||||
@@ -114,6 +115,7 @@ export const DEFAULT_POSTGRES_OPTIONS: SchemaDiffCompareOptions = {
|
||||
cascadeDelete: false,
|
||||
sequenceLastValues: true,
|
||||
compareColumnOrder: false,
|
||||
compareCharset: true,
|
||||
ignoreTableNameCase: false,
|
||||
ignoreColumnNameCase: false,
|
||||
tableIncludePattern: "",
|
||||
@@ -151,6 +153,7 @@ export const DEFAULT_MYSQL_OPTIONS: SchemaDiffCompareOptions = {
|
||||
cascadeDelete: false,
|
||||
sequenceLastValues: false,
|
||||
compareColumnOrder: false,
|
||||
compareCharset: true,
|
||||
ignoreTableNameCase: false,
|
||||
ignoreColumnNameCase: false,
|
||||
tableIncludePattern: "",
|
||||
|
||||
Reference in new issue
Block a user