Check booking, job, and assignment records for dangling references
A dangling reference is a saved record that points to a workspace, client, vehicle, or chauffeur that is missing or does not match. Use this guide to find each one, repair it only from a real saved record, or quarantine it until it is fixed.
What to check, in order
Work through the lists in this order. A record that fails an earlier check is not used for a later step.
Bookings
Open every booking, including Quote, confirmed, complete, and any job or run linked to a booking. Check that each booking opens in the correct company workspace and that the workspace on the booking matches the workspace of the signed-in company.
Client and passenger references
Check that the booker client on each booking opens to a real customer record in the same workspace, and that a separate passenger contact, when given, is stored on that booking and not copied from another booking.
Assignments
Check each assignment on a booking. The assigned chauffeur and the assigned vehicle must each open to a real record in the same workspace, for the pickup date on the booking.
Vehicle and daily check references
Check each daily check against its vehicle and date. The check must name the vehicle that was checked, and the vehicle must be the vehicle assigned for that date when a run uses that check for readiness.
Service, draft, issue, and invoice references
Check each service log against its vehicle and item, each message draft against its booking, each issue against its booking and customer, and each invoice or receipt against its booking and customer.
Remediation rules by dangling reference
Use the rule for the reference that is missing or mismatched. Do not use a rule from another row.
Booking with no workspace, or workspace does not match
Check: the booking does not open in any signed-in workspace, or it opens in a workspace that is not the company that took the booking. Repair: stop. Do not move a booking to another workspace. Quarantine: keep the booking out of the day board and reports, hold any draft on it, and ask the owner or manager to recover the record through the company workspace that created it. A booking with no workspace never counts toward dispatch.
Booking with a missing client or booker
Check: the booker name, phone, or email is present on the booking, but no customer record for that booker exists in the same workspace. Repair: create the customer record first from the contact details on the booking and the customer confirmation, then link the booking to that record. Quarantine: if the booker cannot be confirmed, keep the booking in Quote status, do not confirm it, and do not draft a confirmation message.
Booking with a job, run, or draft that has no booking
Check: a run, job, assignment, message draft, issue, or invoice names a booking that cannot be opened, or names a booking in another workspace. Repair: relink only when the trip facts on the orphan record match one real booking in the same workspace, including service, pickup, drop off, date, and pickup time. Quarantine: if the match is not exact, hold the run, draft, issue, or invoice out of the schedule and out of reports until staff confirm the correct booking with the booker or passenger.
Assignment with a missing chauffeur
Check: the booking names a chauffeur, but no chauffeur record with that name exists in the same workspace, or the record is deactivated. Repair: link the booking only to a real chauffeur record that the owner or manager confirms for that date, then recheck days off, certificate expiry, and the minimum gap. Quarantine: clear the assignment, flag the run as no chauffeur, and run auto assign or assign by hand. Never keep a chauffeur name with no record behind it.
Assignment with a missing vehicle
Check: the booking names a vehicle, but no vehicle record with that plate or name exists in the same workspace. Repair: link the booking only to a real vehicle record that the owner or manager confirms, then recheck the daily check, out of service state, permit and inspection dates, and overdue service for the pickup date. Quarantine: clear the vehicle assignment, flag the run as vehicle not ready, and never dispatch the run on a guessed vehicle.
Assignment with a mismatched chauffeur and vehicle
Check: the assigned vehicle is the home vehicle of a different chauffeur, the assigned chauffeur is marked off for that date, or the vehicle is not Ready for that date. Repair: for a relief chauffeur, use only the car of a chauffeur who is off that day and whose car is free that day. For a full time chauffeur, use that chauffeur home vehicle when it is Ready. Quarantine: if neither rule matches, clear the assignment, flag the reason on the row, and reassign. A mismatched assignment never stays on the day board.
Daily check with a missing or mismatched vehicle
Check: the check names a vehicle that cannot be opened, or the check date does not match the date the vehicle is asked to run. Repair: re-enter the check for the correct vehicle and date, with odometer, fuel, issues, and photos for that vehicle. Quarantine: treat the vehicle as not checked for that date, flag it as not ready, and do not use the check to clear a run.
Service log with a missing vehicle or item
Check: the log names a vehicle that cannot be opened, or an item that is not on the 14 item livery schedule for the workspace. Repair: relink the log only to the real vehicle and item confirmed by the shop record, with date, odometer, shop, and cost for that vehicle. Quarantine: do not reset the due date from an orphan log, and keep the vehicle flagged until a valid log for that vehicle and item is saved.
Safe repair and quarantine rules that apply to every row
These rules keep a repair from creating a new mismatch.
- Never change the workspace on a booking, job, assignment, check, log, draft, issue, or invoice to make a reference match.
- Never delete a record to clear a dangling reference. Keep the record, flag the reason in words on the row, and keep it out of the day board and reports until it is repaired.
- Never create a placeholder client, chauffeur, or vehicle to close a gap. Add a real record first, with the details confirmed by the customer, the chauffeur, or the shop, then link it.
- Never copy a client, vehicle, or chauffeur reference from another booking, another date, or another workspace. Each link must be confirmed for the record and date it is used on.
- When a reference is missing, hold the dependent step. A booking with no confirmed client is not confirmed. A run with no chauffeur or no Ready vehicle is not dispatched. A draft with no booking is not approved or sent.
- After any repair, recheck the full chain for that run. Read the booking, the assigned chauffeur, the assigned vehicle, the daily check for the pickup date, and the flag on the row before you apply the assignment.
- Record what was repaired or quarantined on the booking, with who did it and when, and no secret or personal note in the log detail.
Duplicate identity checks for drivers, vehicles, and bookings
Use these checks before the orphan checks above. A duplicate record with the same certificate number, plate, or booking reference can pass a name check and still create two records for one driver, one vehicle, or one booking. Blank values never group. Two records with blank certificate numbers or blank plates stay separate until a real value is entered on each record.
Driver certificate number
List chauffeur records in one workspace by normalized certificate number, trimmed, in upper case, with spaces and hyphens removed for comparison. Two active records with the same normalized certificate number are duplicates of one driver. Keep both records flagged, assign neither until the owner or manager names one record to keep, then use the merge guide to move bookings, files, days off, and role links to the keeper. A matching certificate number is stronger than a matching name. Do not merge on name alone.
Vehicle plate and permit number
List vehicle records in one workspace by normalized plate and by normalized permit number, trimmed, in upper case, with spaces and hyphens removed for comparison. Two active records with the same normalized plate or the same normalized permit number are duplicates of one vehicle. Keep both vehicles out of assignment until the owner or manager names one record to keep, then move daily checks, odometer readings, service entries, and out of service history to the keeper. Color and type never group vehicles, since several vehicles can share color and type.
Booking reference and public token
List bookings in one workspace by reference code and by public token. Two bookings with the same reference code or the same public token are duplicates of one booking. Keep the second booking in Quote status and out of the day board until staff confirm with the booker or passenger which booking is the real run. A public token identifies one booking for the customer link. Never copy a reference code or a public token from another booking, and never reuse a token after a booking is saved.
Conflicting records that stay separate
Two chauffeurs with the same name but different certificate numbers, two vehicles with the same name but different plates, and a booker and a passenger with the same phone number stay separate. A shared phone, a shared inbox, or a shared name does not make one record. Check certificate number, plate, and contact details with the person before you merge. Use the merge guide for the fixed key for each record type.
- Search the chauffeur list by normalized certificate number before you add a chauffeur. Search the vehicle list by normalized plate and permit number before you add a vehicle. Search the booking list by reference code before you save a booking.
- Count records before a merge and count again on the keeper after the move. The keeper count after the move must equal the keeper count before plus the duplicate count before for each category. See the merge guide for the count and retire steps.
Audit queries to verify zero orphans or duplicates remain
Run these read-only checks in one workspace after any repair or merge, and before you confirm a booking or apply an assignment. Each query lists records that still point to a missing record or that still share one identity value. A clean workspace returns zero rows for every query. Keep the tenant filter on every query, so the check stays inside one workspace. Confirm the table and column names against migrations/0002_app.sql for your build before you run the queries. The queries change no record.
Each query is capped at 200 rows with LIMIT 200, the maximum list page size in the assign runs guide, so a workspace with many orphans or duplicates cannot return an unbounded result set. A result of 200 rows means more records are present than the cap shows. Quarantine the listed records first, then re-run the same query with the same tenant filter and work through the next 200 rows in the same order until the query returns fewer than 200 rows. Do not remove the tenant filter or the cap to list the whole set at once.
Bookings with no workspace or no customer
Lists bookings in one workspace where the customer link finds no customer in the same workspace. Any row is an orphan that must be quarantined in Quote status until a real customer record is created and linked under the remediation rules above.
SELECT b.id, b.reference_code FROM bookings b LEFT JOIN customers c ON c.id = b.customer_id AND c.tenant_id = b.tenant_id WHERE b.tenant_id = :workspace AND c.id IS NULL LIMIT 200;Runs with no chauffeur or no vehicle
Lists confirmed runs where the assigned chauffeur or assigned vehicle finds no matching record in the same workspace. Any row stays flagged as no chauffeur or vehicle not ready and is never dispatched.
SELECT b.id, b.reference_code FROM bookings b LEFT JOIN chauffeurs d ON d.id = b.chauffeur_id AND d.tenant_id = b.tenant_id LEFT JOIN vehicles v ON v.id = b.vehicle_id AND v.tenant_id = b.tenant_id WHERE b.tenant_id = :workspace AND (d.id IS NULL OR v.id IS NULL) LIMIT 200;Daily checks with no vehicle or no date
Lists daily checks where the vehicle finds no vehicle in the same workspace or the check date is blank. Any row is treated as not checked for that date and never clears a run for readiness.
SELECT k.id, k.vehicle_id, k.check_date FROM daily_checks k LEFT JOIN vehicles v ON v.id = k.vehicle_id AND v.tenant_id = k.tenant_id WHERE k.tenant_id = :workspace AND (v.id IS NULL OR k.check_date IS NULL) LIMIT 200;Duplicate certificate numbers, plates, permit numbers, and booking references
Lists identity values held by more than one active record in one workspace. Any row is a duplicate that must be merged or retired under the merge guide before assignment. Blank values are excluded, since blank is not an identity.
SELECT certificate_number, COUNT(*) FROM chauffeurs WHERE tenant_id = :workspace AND certificate_number IS NOT NULL AND TRIM(certificate_number) <> '' GROUP BY UPPER(TRIM(certificate_number)) HAVING COUNT(*) > 1 LIMIT 200;Repeat the same grouping with LIMIT 200 for vehicles by plate, for vehicles by permit number, and for bookings by reference code and by public token, with the same tenant filter and the same blank exclusion.
Service logs, drafts, issues, and invoices with no parent record
Lists service logs with no vehicle, drafts with no booking, issues with no booking, and invoices with no booking, each inside one workspace. Any row is held out of dispatch, reports, and invoices until it is relinked to one real record in the same workspace under the remediation rules above.
SELECT s.id FROM service_logs s LEFT JOIN vehicles v ON v.id = s.vehicle_id AND v.tenant_id = s.tenant_id WHERE s.tenant_id = :workspace AND v.id IS NULL LIMIT 200;Run the same left join check with LIMIT 200 for message drafts against bookings, for issues against bookings, and for invoices against bookings, with the same tenant filter.
- Zero rows for every query above is the pass mark for one workspace. Any row means the workspace still has an orphan or a duplicate.
- A query that returns 200 rows is not a clean result. It means the cap was reached. Quarantine those rows and re-run the same query until a run returns fewer than 200 rows.
- Hold any record named by an audit query out of the day board, reports, and invoices until it is repaired or quarantined, and list it for the owner or manager to recover.
- Run the audits again after each repair or merge. Do not confirm a booking, apply an assignment, or approve a draft while its audit query still lists that record.
- Keep the audit result with the booking, with who ran it and when, and no secret or personal note in the log detail.
Uniqueness rules to keep at save time
Keep these rules when a record is saved. A rule holds a save that would create a second active record for one identity, and names the record to check. The rule changes no rate, no pickup time, and no call time. It only stops a second identity from being saved.
Driver
One active chauffeur record per normalized certificate number per workspace. A blank certificate number is allowed to save the record, but the chauffeur cannot be assigned until the certificate is entered, matches the attached document, and is unique in the workspace.
Vehicle
One active vehicle record per normalized plate per workspace, and one active record per normalized permit number per workspace. A blank plate or permit is allowed to save the record, but the vehicle cannot be assigned until the value is entered, matches the attached document, and is unique in the workspace.
Booking
One booking per reference code per workspace, and one booking per public token per workspace. A public token is always entered by the system and is never blank and never reused. A duplicate reference code or token holds the second save for staff to confirm.
Daily check
One daily check per vehicle per check date per workspace. A second check for the same vehicle and date is held for review, so readiness for a pickup date reads from one check only.
- Search before you save, under the duplicate identity checks above. A save that would share one identity is held, not saved as a second record.
- Retiring a duplicate keeps history for reporting. Retire the duplicate record after the recount in the merge guide. Do not delete it in a way that breaks past bookings.
- After any uniqueness hold, correct the named record first, then re-read the booking, the assigned chauffeur, the assigned vehicle, the daily check for the pickup date, and the flag on the row before you apply the assignment.
How to check the result
After the pass, the day board and the lists should agree.
- Every confirmed booking opens in the correct workspace and links to a real customer record in that workspace.
- Every assigned run links to a real chauffeur and a real vehicle in the same workspace, for the pickup date, with no days off, certificate, readiness, or minimum gap conflict.
- Every daily check and service log opens for its vehicle, and every draft, issue, and invoice opens for its booking.
- Every audit query in the audit section above returns zero rows for one workspace, checked after any repair or merge and before dispatch.
- Any record that could not be repaired is flagged in words, kept out of dispatch and reports, and listed for the owner or manager to recover. No flagged run is counted as covered.
Keep every reference tied to a real record
Run this check before you confirm a booking, apply an assignment, or approve a message.