MCPcopy
hub / github.com/chartdb/chartdb / compareCheckConstraints

Function compareCheckConstraints

src/lib/domain/diff/diff-check/diff-check.ts:1174–1315  ·  view source on GitHub ↗
({
    tableId,
    oldCheckConstraints,
    newCheckConstraints,
    diffMap,
    changedTables,
    changedCheckConstraints,
    attributes,
    changedTablesAttributes,
    changedCheckConstraintsAttributes,
    changeTypes,
    checkConstraintMatcher,
}: {
    tableId: string;
    oldCheckConstraints: DBCheckConstraint[];
    newCheckConstraints: DBCheckConstraint[];
    diffMap: DiffMap;
    changedTables: Map<string, boolean>;
    changedCheckConstraints: Map<string, boolean>;
    attributes?: CheckConstraintDiffAttribute[];
    changedTablesAttributes?: TableDiffAttribute[];
    changedCheckConstraintsAttributes?: CheckConstraintDiffAttribute[];
    changeTypes?: CheckConstraintDiff['type'][];
    checkConstraintMatcher: (
        constraint: DBCheckConstraint,
        constraints: DBCheckConstraint[]
    ) => DBCheckConstraint | undefined;
})

Source from the content-addressed store, hash-verified

1172
1173// Compare check constraints between tables
1174function compareCheckConstraints({
1175 tableId,
1176 oldCheckConstraints,
1177 newCheckConstraints,
1178 diffMap,
1179 changedTables,
1180 changedCheckConstraints,
1181 attributes,
1182 changedTablesAttributes,
1183 changedCheckConstraintsAttributes,
1184 changeTypes,
1185 checkConstraintMatcher,
1186}: {
1187 tableId: string;
1188 oldCheckConstraints: DBCheckConstraint[];
1189 newCheckConstraints: DBCheckConstraint[];
1190 diffMap: DiffMap;
1191 changedTables: Map<string, boolean>;
1192 changedCheckConstraints: Map<string, boolean>;
1193 attributes?: CheckConstraintDiffAttribute[];
1194 changedTablesAttributes?: TableDiffAttribute[];
1195 changedCheckConstraintsAttributes?: CheckConstraintDiffAttribute[];
1196 changeTypes?: CheckConstraintDiff['type'][];
1197 checkConstraintMatcher: (
1198 constraint: DBCheckConstraint,
1199 constraints: DBCheckConstraint[]
1200 ) => DBCheckConstraint | undefined;
1201}) {
1202 // If changeTypes is empty array, don't check any changes
1203 if (changeTypes && changeTypes.length === 0) {
1204 return;
1205 }
1206
1207 // If changeTypes is undefined, check all types
1208 const typesToCheck = changeTypes ?? ['added', 'removed', 'changed'];
1209
1210 // For structural changes (added/removed constraints), add to changedTables unless
1211 // changedTablesAttributes is explicitly set to empty array
1212 const shouldAddToChangedTables =
1213 changedTablesAttributes === undefined ||
1214 changedTablesAttributes.length > 0;
1215
1216 // Check for added check constraints
1217 if (typesToCheck.includes('added')) {
1218 for (const newConstraint of newCheckConstraints) {
1219 if (!checkConstraintMatcher(newConstraint, oldCheckConstraints)) {
1220 diffMap.set(
1221 getDiffMapKey({
1222 diffObject: 'checkConstraint',
1223 objectId: newConstraint.id,
1224 }),
1225 {
1226 object: 'checkConstraint',
1227 type: 'added',
1228 newCheckConstraint: newConstraint,
1229 tableId,
1230 }
1231 );

Callers 1

compareTableContentsFunction · 0.85

Calls 2

getDiffMapKeyFunction · 0.85
shouldAddToChangedMapFunction · 0.85

Tested by

no test coverage detected