classTableTransitions
final class TableTransitions
Works out what a statement did to each table, by comparing the two shadows.
Nothing records what a rewritten statement changed, so it is recovered by pairing the rows of the shadow before against the rows after. Where a table declares a key, the pairing is by that key, which is what tells an update apart from a delete followed by an insert; where it declares none, only an identical row can be said to be the same row.
An UPDATE is the one case where the pairing is known rather than guessed: the result rows carry both the old key and the new one, so those pairs are taken first and the guessing only fills in what they leave.
Type Aliases§
Row = import from TableDefinitionMethods§
public function __construct(
private TableDefinitionRegistry $registry,
private RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch(),
private MutationRowIdentity $identity = new \ZtdQuery\Shadow\Mutation\MutationRowIdentity(),
)Parameters
$registry | TableDefinitionRegistry | Answers what a table declares |
$rows | RowMatch | Finds a row among rows |
$identity | MutationRowIdentity | Reads the old and new key off a result row |
Test cases 15
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescoversTableTransitionsTest::testBetweenPairsOnlyIdenticalRowsWhereTheTableDeclaresNoKeycoversTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecoversTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcoversTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcoversTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocoversTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocoversTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescoversTableTransitionsTest::testPairByIdentityLeavesARowNoResultRowSpeaksForcoversTableTransitionsTest::testPairByIdentityTakesThePairsAnUpdateToldUsAboutcoversTableTransitionsTest::testPairByKeyLeavesARowAlreadyPairedOffcoversTableTransitionsTest::testPairByKeyLeavesARowTheKeyNoLongerMatchescoversTableTransitionsTest::testPairByKeyPairsOffWhateverTheKeyStillMatchescoversTableTransitionsTest::testPairIdenticalPairsOffOnlyRowsThatAreWhatTheyWerecoversTableTransitionsTest::testUnmatchedAnswersTheRowsNothingWasPairedWithcovers
Calls 2
public function of(
ShadowStore $before,
ShadowStore $after,
ShadowMutation $mutation,
array<int, Row> $resultRows,
): list<TableTransition>Answers what happened to every table the statement could have touched.
Parameters
$before | ShadowStore | Shadow as it was |
$after | ShadowStore | Shadow as it became |
$mutation | ShadowMutation | Statement that was simulated |
$resultRows | array<int, Row> | Rows the rewritten statement read back |
Returns
list<TableTransition> One entry per table something happened toTest cases 3
TableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocovers and callsTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocovers and callsTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescovers and calls
Called from 1
Calls 6
- method-call ShadowMutation::tableName() line 58
- function-call
array_keysline 60 - method-call ShadowStore::getAll() line 60
- method-call TableDefinitionRegistry::get() line 61
- method-call TableTransitions::between() line 62
- method-call ShadowStore::get() line 64
public function between(
string $table,
array<int, Row> $beforeRows,
array<int, Row> $afterRows,
list<string> $primaryKeys,
array<int, Row> $identityRows,
): TableTransitionAnswers what happened to one table.
Parameters
Returns
TableTransition What happened to itTest cases 8
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescovers and callsTableTransitionsTest::testBetweenPairsOnlyIdenticalRowsWhereTheTableDeclaresNoKeycovers and callsTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecovers and callsTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcovers and callsTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcovers and callsTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocoversTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocoversTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescovers
Called from 1
Calls 8
- new RowPairing line 95
- method-call TableTransitions::pairIdentical() line 97
- method-call TableTransitions::pairByIdentity() line 99
- method-call TableTransitions::pairByKey() line 100
- new TableTransition line 103
- method-call TableTransitions::unmatched() line 105
- method-call RowPairing::beforePositions() line 105
- method-call RowPairing::changes() line 106
public function pairIdentical(
RowPairing $pairing,
array<int, Row> $beforeRows,
array<int, Row> $afterRows,
): voidPairs off the rows that are the same row because they are the same row.
Where a table declares no key there is nothing to say that two rows that differ were once each other, so only an identical row is paired, and no row is ever said to have changed.
Parameters
$pairing | RowPairing | Pairs made so far, added to in place |
$beforeRows | array<int, Row> | Rows as they were |
$afterRows | array<int, Row> | Rows as they became |
Test cases 2
Called from 1
Calls 3
- method-call RowMatch::positionOfIdentical() line 124
- method-call RowPairing::afterPositions() line 124
- method-call RowPairing::pair() line 126
public function pairByIdentity(
RowPairing $pairing,
array<int, Row> $beforeRows,
array<int, Row> $afterRows,
list<string> $primaryKeys,
array<int, Row> $identityRows,
): voidPairs off the rows an UPDATE told us about.
A result row carries both the key the row had and the key it has, so these pairs are known rather than guessed, and taking them first is what keeps a changed key from looking like a delete and an insert.
Parameters
$pairing | RowPairing | Pairs made so far, added to in place |
$beforeRows | array<int, Row> | Rows as they were |
$afterRows | array<int, Row> | Rows as they became |
$primaryKeys | list<string> | Columns that identify one row |
$identityRows | array<int, Row> | Result rows carrying both the old key and the new one |
Test cases 9
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescoversTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecoversTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcoversTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcoversTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocoversTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocoversTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescoversTableTransitionsTest::testPairByIdentityLeavesARowNoResultRowSpeaksForcovers and callsTableTransitionsTest::testPairByIdentityTakesThePairsAnUpdateToldUsAboutcovers and calls
Called from 1
Calls 5
- method-call MutationRowIdentity::extract() line 152
- method-call RowMatch::positionOfSameKey() line 153
- method-call RowPairing::beforePositions() line 157
- method-call RowPairing::afterPositions() line 163
- method-call RowPairing::pair() line 168
public function pairByKey(
RowPairing $pairing,
array<int, Row> $beforeRows,
array<int, Row> $afterRows,
list<string> $primaryKeys,
): voidPairs off whatever the key can still match.
Parameters
$pairing | RowPairing | Pairs made so far, added to in place |
$beforeRows | array<int, Row> | Rows as they were |
$afterRows | array<int, Row> | Rows as they became |
$primaryKeys | list<string> | Columns that identify one row |
Test cases 10
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescoversTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecoversTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcoversTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcoversTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocoversTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocoversTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescoversTableTransitionsTest::testPairByKeyLeavesARowAlreadyPairedOffcovers and callsTableTransitionsTest::testPairByKeyLeavesARowTheKeyNoLongerMatchescovers and callsTableTransitionsTest::testPairByKeyPairsOffWhateverTheKeyStillMatchescovers and calls
Called from 1
Calls 5
- function-call
in_arrayline 183 - method-call RowPairing::beforePositions() line 183
- method-call RowMatch::positionOfSameKey() line 186
- method-call RowPairing::afterPositions() line 190
- method-call RowPairing::pair() line 195
Answers the rows nothing was paired with, which are the ones that went.
Parameters
$rows | array<int, Row> | Rows as they were |
$matched | list<int> | Positions that were paired off |
Returns
list<Row> The rows that were notTest cases 9
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescoversTableTransitionsTest::testBetweenPairsOnlyIdenticalRowsWhereTheTableDeclaresNoKeycoversTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecoversTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcoversTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcoversTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocoversTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocoversTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescoversTableTransitionsTest::testUnmatchedAnswersTheRowsNothingWasPairedWithcovers and calls
Called from 1
Calls 1
- function-call
in_arrayline 211
Private surface 3§
Implementation details, listed for orientation only.
private TableDefinitionRegistry $registryprivate RowMatch $rows = new \ZtdQuery\Shadow\Row\RowMatch()private MutationRowIdentity $identity = new \ZtdQuery\Shadow\Mutation\MutationRowIdentity()Test cases 19§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 15
TableTransitionsTest::testBetweenPairsARowByTheOldKeyTheResultCarriescovers and callsTableTransitionsTest::testBetweenPairsOnlyIdenticalRowsWhereTheTableDeclaresNoKeycovers and callsTableTransitionsTest::testBetweenPairsTwoRowsSharingAKeyOneToOnecovers and callsTableTransitionsTest::testBetweenReadsARowThatChangedAsUpdatedcovers and callsTableTransitionsTest::testBetweenReadsARowThatIsNoLongerThereAsDeletedcovers and callsTableTransitionsTest::testOfAnswersOneEntryPerTableSomethingHappenedTocovers and callsTableTransitionsTest::testOfLeavesOutATableNothingHappenedTocovers and callsTableTransitionsTest::testOfReadsTheResultRowsOnlyForTheTableAnUpdateNamescovers and callsTableTransitionsTest::testPairByIdentityLeavesARowNoResultRowSpeaksForcovers and callsTableTransitionsTest::testPairByIdentityTakesThePairsAnUpdateToldUsAboutcovers and callsTableTransitionsTest::testPairByKeyLeavesARowAlreadyPairedOffcovers and callsTableTransitionsTest::testPairByKeyLeavesARowTheKeyNoLongerMatchescovers and callsTableTransitionsTest::testPairByKeyPairsOffWhateverTheKeyStillMatchescovers and callsTableTransitionsTest::testPairIdenticalPairsOffOnlyRowsThatAreWhatTheyWerecovers and callsTableTransitionsTest::testUnmatchedAnswersTheRowsNothingWasPairedWithcovers and calls
Other tests reaching this symbol 4
SessionTestcallsReferentialIntegrityEnforcerTestcallsShadowApplicationTestcallsStatementSimulatorTestcalls