MCPcopy
hub / github.com/chartdb/chartdb / compareTables

Function compareTables

src/lib/domain/diff/diff-check/diff-check.ts:327–564  ·  view source on GitHub ↗
({
    diagram,
    newDiagram,
    diffMap,
    changedTables,
    attributes,
    changedTablesAttributes,
    changeTypes,
    tableMatcher,
}: {
    diagram: Diagram;
    newDiagram: Diagram;
    diffMap: DiffMap;
    changedTables: Map<string, boolean>;
    attributes?: TableDiffAttribute[];
    changedTablesAttributes?: TableDiffAttribute[];
    changeTypes?: TableDiff['type'][];
    tableMatcher: (table: DBTable, tables: DBTable[]) => DBTable | undefined;
})

Source from the content-addressed store, hash-verified

325
326// Compare tables between diagrams
327function compareTables({
328 diagram,
329 newDiagram,
330 diffMap,
331 changedTables,
332 attributes,
333 changedTablesAttributes,
334 changeTypes,
335 tableMatcher,
336}: {
337 diagram: Diagram;
338 newDiagram: Diagram;
339 diffMap: DiffMap;
340 changedTables: Map<string, boolean>;
341 attributes?: TableDiffAttribute[];
342 changedTablesAttributes?: TableDiffAttribute[];
343 changeTypes?: TableDiff['type'][];
344 tableMatcher: (table: DBTable, tables: DBTable[]) => DBTable | undefined;
345}) {
346 const oldTables = diagram.tables || [];
347 const newTables = newDiagram.tables || [];
348
349 // If changeTypes is empty array, don't check any changes
350 if (changeTypes && changeTypes.length === 0) {
351 return;
352 }
353
354 // If changeTypes is undefined, check all types
355 const typesToCheck = changeTypes ?? ['added', 'removed', 'changed'];
356
357 // Check for added tables
358 if (typesToCheck.includes('added')) {
359 for (const newTable of newTables) {
360 if (!tableMatcher(newTable, oldTables)) {
361 diffMap.set(
362 getDiffMapKey({
363 diffObject: 'table',
364 objectId: newTable.id,
365 }),
366 {
367 object: 'table',
368 type: 'added',
369 tableAdded: newTable,
370 }
371 );
372 changedTables.set(newTable.id, true);
373 }
374 }
375 }
376
377 // Check for removed tables
378 if (typesToCheck.includes('removed')) {
379 for (const oldTable of oldTables) {
380 if (!tableMatcher(oldTable, newTables)) {
381 diffMap.set(
382 getDiffMapKey({
383 diffObject: 'table',
384 objectId: oldTable.id,

Callers 1

generateDiffFunction · 0.85

Calls 3

getDiffMapKeyFunction · 0.85
shouldAddToChangedMapFunction · 0.85
areCommentsDifferentFunction · 0.85

Tested by

no test coverage detected