feat(schema-diff): compare routines across same-structure databases
This commit is contained in:
1 parent
bd2ac50ac1
commit
1191118b5c
31 files changed
+2256
-281
No files matched your search
@@ -55,6 +55,10 @@ const DATABASE_TYPE_OBJECTS = new Map<DatabaseType, SidebarObjectKind[]>([
|
||||
["oceanbase-oracle", OCEANBASE_ORACLE_OBJECTS],
|
||||
["xugu", XUGU_OBJECTS],
|
||||
["mysql", MYSQL_OBJECTS],
|
||||
// Explicit entry so schema-diff routine gating can opt in without relying on the
|
||||
// unknown-type ROUTINE_OBJECTS fallback. Keep the same object set the fallback
|
||||
// already used (no TRIGGER/SEQUENCE expansion in this change).
|
||||
["sqlserver", ROUTINE_OBJECTS],
|
||||
// table and view
|
||||
["sqlite", TABLE_VIEW_OBJECTS],
|
||||
["rqlite", TABLE_VIEW_OBJECTS],
|
||||
@@ -119,6 +123,49 @@ export function databaseObjectCapabilities(dbType?: DatabaseType): DatabaseObjec
|
||||
};
|
||||
}
|
||||
|
||||
const SCHEMA_DIFF_ROUTINE_KINDS = ["PROCEDURE", "FUNCTION"] as const;
|
||||
|
||||
/** Same-dialect families with verified list_objects + get_object_source (or PG catalog) paths. */
|
||||
const SCHEMA_DIFF_ROUTINE_FAMILY = new Map<DatabaseType, "postgres" | "mysql" | "sqlserver">([
|
||||
["postgres", "postgres"],
|
||||
["opengauss", "postgres"],
|
||||
["gaussdb", "postgres"],
|
||||
["kwdb", "postgres"],
|
||||
["kingbase", "postgres"],
|
||||
["highgo", "postgres"],
|
||||
["uxdb", "postgres"],
|
||||
["vastbase", "postgres"],
|
||||
["redshift", "postgres"],
|
||||
["mysql", "mysql"],
|
||||
["sqlserver", "sqlserver"],
|
||||
]);
|
||||
|
||||
/**
|
||||
* Schema Diff routine compare is limited to an allowlist of same-dialect families.
|
||||
* Sidebar may list routines for more engines (oracle/hive/…); those stay out of
|
||||
* schema-diff until a verified compare path lands. Cross-family pairs never match.
|
||||
*/
|
||||
export function supportsSchemaDiffRoutines(dbType?: DatabaseType): boolean {
|
||||
if (!dbType || !SCHEMA_DIFF_ROUTINE_FAMILY.has(dbType)) return false;
|
||||
const { sidebarObjects, sourceReadable } = databaseObjectCapabilities(dbType);
|
||||
return SCHEMA_DIFF_ROUTINE_KINDS.some((kind) => sidebarObjects.includes(kind) && sourceReadable.includes(kind));
|
||||
}
|
||||
|
||||
export function schemaDiffRoutineObjectTypes(dbType?: DatabaseType): Array<"PROCEDURE" | "FUNCTION"> {
|
||||
if (!supportsSchemaDiffRoutines(dbType)) return [];
|
||||
const { sidebarObjects, sourceReadable } = databaseObjectCapabilities(dbType);
|
||||
return SCHEMA_DIFF_ROUTINE_KINDS.filter((kind) => sidebarObjects.includes(kind) && sourceReadable.includes(kind));
|
||||
}
|
||||
|
||||
export function schemaDiffRoutineObjectTypesIntersection(sourceDbType?: DatabaseType, targetDbType?: DatabaseType): Array<"PROCEDURE" | "FUNCTION"> {
|
||||
if (!sourceDbType || !targetDbType) return [];
|
||||
const sourceFamily = SCHEMA_DIFF_ROUTINE_FAMILY.get(sourceDbType);
|
||||
const targetFamily = SCHEMA_DIFF_ROUTINE_FAMILY.get(targetDbType);
|
||||
if (!sourceFamily || sourceFamily !== targetFamily) return [];
|
||||
const sourceTypes = new Set(schemaDiffRoutineObjectTypes(sourceDbType));
|
||||
return schemaDiffRoutineObjectTypes(targetDbType).filter((kind) => sourceTypes.has(kind));
|
||||
}
|
||||
|
||||
export function sidebarObjectKindsForDatabase(dbType?: DatabaseType): SidebarObjectKind[] {
|
||||
if (!dbType) return [...TABLE_VIEW_OBJECTS];
|
||||
return DATABASE_TYPE_OBJECTS.get(dbType) ?? [...ROUTINE_OBJECTS];
|
||||
|
||||
Reference in new issue
Block a user