fix(schema-diff): correct Oracle/JDBC column, index and view diffs
This commit is contained in:
7 files changed
+1095
-95
No files matched your search
@@ -322,3 +322,47 @@ test("skips table list loading for routines-only compares", async () => {
|
||||
assert.equal(apiMock.listFunctions.mock.calls.length, 2);
|
||||
assert.deepEqual(apiMock.prepareSchemaDiff.mock.calls[0]?.[0]?.sourceTables, []);
|
||||
});
|
||||
|
||||
test("resolves the JDBC engine dialect from the connection's product type", async () => {
|
||||
// 「Oracle (JDBC)」这类连接的 db_type 是 jdbc,后端 DialectKind 认不出它:对话框把产品类型
|
||||
// 解析出来传进 sourceEngineDbType/targetEngineDbType 后,方言(以及视图比较)才成立。
|
||||
apiMock.prepareSchemaDiff.mockClear();
|
||||
apiMock.prepareSchemaDiff.mockResolvedValue({
|
||||
diffs: [],
|
||||
functionDiffs: [],
|
||||
sequenceDiffs: [],
|
||||
ruleDiffs: [],
|
||||
ownerDiffs: [],
|
||||
renameCandidates: [],
|
||||
syncSql: "",
|
||||
rollbackSyncSql: "",
|
||||
});
|
||||
|
||||
const session = startSchemaDiffSession(
|
||||
{
|
||||
sourceConnectionId: "jdbc-src",
|
||||
sourceDatabase: "XE",
|
||||
sourceSchema: "DBX_TEST",
|
||||
targetConnectionId: "jdbc-dst",
|
||||
targetDatabase: "XE",
|
||||
targetSchema: "DBX_TGT",
|
||||
sourceDbType: "jdbc",
|
||||
targetDbType: "jdbc",
|
||||
sourceEngineDbType: "oracle",
|
||||
targetEngineDbType: "oracle",
|
||||
options: {},
|
||||
ignoreComments: false,
|
||||
label: "jdbc oracle",
|
||||
},
|
||||
{ tableListLoader: { load: vi.fn().mockResolvedValue([]) } },
|
||||
);
|
||||
|
||||
await waitForSession(session);
|
||||
|
||||
assert.equal(session.status, "completed");
|
||||
const payload = apiMock.prepareSchemaDiff.mock.calls[0]?.[0];
|
||||
assert.equal(payload?.sourceDialect, "oracle");
|
||||
assert.equal(payload?.targetDialect, "oracle");
|
||||
// 部署脚本按目标产品类型(而不是 jdbc)生成。
|
||||
assert.equal(payload?.databaseType, "oracle");
|
||||
});
|
||||
@@ -31,6 +31,13 @@ export interface SchemaDiffSessionConfig {
|
||||
targetSchema: string;
|
||||
sourceDbType: string;
|
||||
targetDbType: DatabaseType;
|
||||
/**
|
||||
* Product type behind a JDBC `sourceDbType`/`targetDbType` (see
|
||||
* `schemaDiffEngineDatabaseType`). Only the diff engine's dialect/profile decisions use
|
||||
* it: metadata loading, progress phases and option defaults keep the raw db types.
|
||||
*/
|
||||
sourceEngineDbType?: DatabaseType;
|
||||
targetEngineDbType?: DatabaseType;
|
||||
options: SchemaDiffCompareOptions;
|
||||
ignoreComments: boolean;
|
||||
label: string;
|
||||
@@ -56,6 +63,11 @@ export interface SchemaDiffSessionDependencies {
|
||||
|
||||
const sessions = reactive(new Map<string, SchemaDiffSession>());
|
||||
|
||||
function schemaDiffDialect(dbType: DatabaseType | string | undefined, explicit: string | undefined): string | undefined {
|
||||
if (explicit) return normalizeDialectKind(explicit);
|
||||
return dbType ? databaseTypeToDialectKind(dbType as DatabaseType) : undefined;
|
||||
}
|
||||
|
||||
function cloneOptions(options: SchemaDiffCompareOptions): SchemaDiffCompareOptions {
|
||||
return {
|
||||
...options,
|
||||
@@ -209,7 +221,7 @@ async function runSchemaDiffSession(session: SchemaDiffSession, dependencies: Sc
|
||||
sourceOwners,
|
||||
targetOwners,
|
||||
tableMappings: sessionOptions.selectedTables === undefined ? undefined : sessionOptions.tableMappings,
|
||||
databaseType: input.targetDbType,
|
||||
databaseType: input.targetEngineDbType ?? input.targetDbType,
|
||||
targetSchema: schemaDiffDeployTargetSchema(input.targetDbType, input.targetDatabase, input.targetSchema),
|
||||
ignoreComments: input.ignoreComments,
|
||||
cascadeDelete: sessionOptions.cascadeDelete ?? false,
|
||||
@@ -226,8 +238,8 @@ async function runSchemaDiffSession(session: SchemaDiffSession, dependencies: Sc
|
||||
.map((value) => value.trim())
|
||||
.filter(Boolean)
|
||||
: undefined,
|
||||
sourceDialect: sessionOptions.sourceDialect ? normalizeDialectKind(sessionOptions.sourceDialect) : input.sourceDbType ? databaseTypeToDialectKind(input.sourceDbType as DatabaseType) : undefined,
|
||||
targetDialect: sessionOptions.targetDialect ? normalizeDialectKind(sessionOptions.targetDialect) : input.targetDbType ? databaseTypeToDialectKind(input.targetDbType) : undefined,
|
||||
sourceDialect: schemaDiffDialect(input.sourceEngineDbType ?? input.sourceDbType, sessionOptions.sourceDialect),
|
||||
targetDialect: schemaDiffDialect(input.targetEngineDbType ?? input.targetDbType, sessionOptions.targetDialect),
|
||||
compatibilityThreshold: sessionOptions.compatibilityThreshold ?? 0.5,
|
||||
fieldMappings:
|
||||
sessionOptions.fieldMappings?.map((mapping) => ({
|
||||
|
||||
Reference in new issue
Block a user