Added
TRUSS-INT-010finds a foreign key that points at the wrong table: a single-column*_idkey that references one table while a table named after the column exists and is a different one. Found on Lunar 1.5.0, wherelunar_cart_line_discount.cart_line_idis constrained againstlunar_cartsrather thanlunar_cart_lines, straight from the 2022 migration'sconstrained()call.CartLine::discounts()is abelongsToManythrough that table, so the application writes cart line ids into a column validated against cart ids: an insert only succeeds when that id happens to exist as a cart too,ON DELETE CASCADEfires when the wrong parent goes, so deleting a cart deletes discount rows whosecart_line_idmerely equals that cart's id, and deleting a cart line cascades nothing and leaves orphans. The hard part is not detection, it is silence. Most name mismatches are deliberate and correct: six of the seven mismatches among Lunar's 83 foreign keys are ordinary aliases (merged_id,parent_transaction_id,product_parent_id,product_target_id,value_id,variant_id), so a rule that flagged every mismatch would be wrong 86% of the time, which is the same calibration trap thatTRUSS-INT-007fell into. The test is therefore not "the names differ" but "the name names a table that actually exists, and the key points somewhere else". An alias survives because there is noauthorsormergedstable for its name to name. Ambiguity is silence: candidates resolve plural first then singular, and only when exactly one table matches, so more than one match reports nothing rather than guessing. A prefixed schema is matched through the prefix the referenced table already carries, solunar_tables are neither invisible nor confused with another application's. Morph targets and composite keys are skipped, since neither is named after one table. The rule is high confidence and an error, so it runs under the defaultrecommendedpreset and a CI job runningtruss:doctor --fail-on=errorcan see a new failure on a schema that has not changed.
Full documentation: https://trussphp.com/guides/schema-doctor/