MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / diffTable

Method diffTable

packages/sql/src/schema/SchemaComparator.ts:426–702  ·  view source on GitHub ↗

* Returns the difference between the tables fromTable and toTable. * If there are no differences this method returns the boolean false.

(
    fromTable: DatabaseTable,
    toTable: DatabaseTable,
    inverseTableDiff?: TableDifference,
  )

Source from the content-addressed store, hash-verified

424 * If there are no differences this method returns the boolean false.
425 */
426 diffTable(
427 fromTable: DatabaseTable,
428 toTable: DatabaseTable,
429 inverseTableDiff?: TableDifference,
430 ): TableDifference | false {
431 let changes = 0;
432 const tableDifferences: TableDifference = {
433 name: fromTable.getShortestName(),
434 addedColumns: {},
435 addedForeignKeys: {},
436 addedIndexes: {},
437 addedChecks: {},
438 addedTriggers: {},
439 changedColumns: {},
440 changedForeignKeys: {},
441 changedIndexes: {},
442 changedChecks: {},
443 changedTriggers: {},
444 removedColumns: {},
445 removedForeignKeys: {},
446 removedIndexes: {},
447 removedChecks: {},
448 removedTriggers: {},
449 renamedColumns: {},
450 renamedIndexes: {},
451 fromTable,
452 toTable,
453 };
454
455 if (this.#platform.supportsComments() && this.diffComment(fromTable.comment, toTable.comment)) {
456 tableDifferences.changedComment = toTable.comment;
457 this.log(`table comment changed for ${tableDifferences.name}`, {
458 fromTableComment: fromTable.comment,
459 toTableComment: toTable.comment,
460 });
461 changes++;
462 }
463
464 if (
465 diffPartitioning(fromTable.getPartitioning(), toTable.getPartitioning(), this.#platform.getDefaultSchemaName())
466 ) {
467 tableDifferences.changedPartitioning = {
468 from: fromTable.getPartitioning(),
469 to: toTable.getPartitioning(),
470 };
471 this.log(`table partitioning changed for ${tableDifferences.name}`, {
472 fromPartitioning: fromTable.getPartitioning(),
473 toPartitioning: toTable.getPartitioning(),
474 });
475 changes++;
476 }
477
478 const fromTableColumns = fromTable.getColumns();
479 const toTableColumns = toTable.getColumns();
480
481 // See if all the columns in "from" table exist in "to" table
482 for (const column of toTableColumns) {
483 if (fromTable.hasColumn(column.name)) {

Callers 2

compareMethod · 0.95

Calls 15

diffCommentMethod · 0.95
logMethod · 0.95
diffColumnMethod · 0.95
detectColumnRenamingsMethod · 0.95
diffIndexMethod · 0.95
detectIndexRenamingsMethod · 0.95
diffExpressionMethod · 0.95
diffEnumItemsMethod · 0.95
diffTriggerMethod · 0.95
diffForeignKeyMethod · 0.95
diffPartitioningFunction · 0.85
getShortestNameMethod · 0.80

Tested by

no test coverage detected