MCPcopy
hub / github.com/chartdb/chartdb / compareIndexes

Function compareIndexes

src/lib/domain/diff/diff-check/diff-check.ts:934–1043  ·  view source on GitHub ↗
({
    tableId,
    oldIndexes,
    newIndexes,
    diffMap,
    changedTables,
    changedIndexes,
    attributes,
    changedTablesAttributes,
    changedIndexesAttributes,
    changeTypes,
    indexMatcher,
    databaseType,
}: {
    tableId: string;
    oldIndexes: DBIndex[];
    newIndexes: DBIndex[];
    diffMap: DiffMap;
    changedTables: Map<string, boolean>;
    changedIndexes: Map<string, boolean>;
    attributes?: IndexDiffAttribute[];
    changedTablesAttributes?: TableDiffAttribute[];
    changedIndexesAttributes?: IndexDiffAttribute[];
    changeTypes?: IndexDiff['type'][];
    indexMatcher: (index: DBIndex, indexes: DBIndex[]) => DBIndex | undefined;
    databaseType: DatabaseType;
})

Source from the content-addressed store, hash-verified

932
933// Compare indexes between tables
934function compareIndexes({
935 tableId,
936 oldIndexes,
937 newIndexes,
938 diffMap,
939 changedTables,
940 changedIndexes,
941 attributes,
942 changedTablesAttributes,
943 changedIndexesAttributes,
944 changeTypes,
945 indexMatcher,
946 databaseType,
947}: {
948 tableId: string;
949 oldIndexes: DBIndex[];
950 newIndexes: DBIndex[];
951 diffMap: DiffMap;
952 changedTables: Map<string, boolean>;
953 changedIndexes: Map<string, boolean>;
954 attributes?: IndexDiffAttribute[];
955 changedTablesAttributes?: TableDiffAttribute[];
956 changedIndexesAttributes?: IndexDiffAttribute[];
957 changeTypes?: IndexDiff['type'][];
958 indexMatcher: (index: DBIndex, indexes: DBIndex[]) => DBIndex | undefined;
959 databaseType: DatabaseType;
960}) {
961 // If changeTypes is empty array, don't check any changes
962 if (changeTypes && changeTypes.length === 0) {
963 return;
964 }
965
966 // If changeTypes is undefined, check all types
967 const typesToCheck = changeTypes ?? ['added', 'removed', 'changed'];
968
969 // For structural changes (added/removed indexes), add to changedTables unless
970 // changedTablesAttributes is explicitly set to empty array
971 const shouldAddToChangedTables =
972 changedTablesAttributes === undefined ||
973 changedTablesAttributes.length > 0;
974
975 // Check for added indexes
976 if (typesToCheck.includes('added')) {
977 for (const newIndex of newIndexes) {
978 if (!indexMatcher(newIndex, oldIndexes)) {
979 diffMap.set(
980 getDiffMapKey({
981 diffObject: 'index',
982 objectId: newIndex.id,
983 }),
984 {
985 object: 'index',
986 type: 'added',
987 newIndex,
988 tableId,
989 }
990 );
991 if (shouldAddToChangedTables) {

Callers 1

compareTableContentsFunction · 0.85

Calls 2

getDiffMapKeyFunction · 0.85
compareIndexPropertiesFunction · 0.85

Tested by

no test coverage detected