* 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,
)
| 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)) { |
no test coverage detected