Guide · Data quality

Booking record integrity: completeness, duplicates and orphans

Run one gate before a booking is confirmed, assigned, approved or invoiced. A booking that fails the gate stays in Quote, stays flagged, and stays out of the day board, reports and invoices until the named record is corrected. No blank is filled from a prior run, a public page, or another workspace.

The completeness gate

Read the gate in this order. A failed row names the field to correct. Correct that record first, then re-read the quote, call time, status and flags. Do not confirm, assign, approve a draft, or issue an invoice for a failed row.

Passenger complete

  • Passenger name is not blank after trimming, and is at most 120 characters
  • Passenger phone is present, at most 30 characters as entered, and 10 to 15 digits after removing punctuation, with the country code included, because chauffeur details go to that phone after Driver confirmed
  • Passengers is a whole number from 1 to 7, and each vehicle carries 7 passengers maximum
  • Booker contact, when supplied, passes the same phone and email checks, and booker and passenger contacts stay as separate fields

Vehicle complete and Ready for the pickup date

  • Vehicle id is present on every Confirmed run, and the id opens to a real vehicle record in the same workspace
  • Daily check result is Ready and the check date equals pickup date in the company timezone, the vehicle is not Out of service, permit and inspection expiry are on or after pickup date, and no service item for that vehicle is overdue
  • Odometer is recorded and is not lower than the last recorded odometer for that vehicle
  • Chauffeur id, when the run is Confirmed, opens to a real chauffeur record in the same workspace, is not marked off for that date, and certificate expiry is on or after pickup date

Date and time complete and consistent

  • Pickup time is present in ISO form, is in the future when the request is sent, and pickup date is the calendar date of pickup time in the company timezone saved by place name
  • Call time equals pickup time minus the saved lead hours setting, 3 hours by default, and is recalculated only when pickup time changes
  • Pickup and drop off are present, at most 200 characters each, with drop off required except for hourly and event service, and flight number and airline are present for an MCI airport arrival
  • Status follows Quote, Confirmed, Driver confirmed, En route, On location, Passenger on board, Complete, plus Cancelled only through the public cancel flow on a Quote or Confirmed booking, with no step skipped

Quote complete

  • Rate, gratuity and all in total are present on the saved quote, in whole dollars on separate lines, with total equal to rate plus gratuity
  • A changed rate in settings applies to new quotes only and never rewrites a saved quote on a booking that already passed this gate
  • When the saved quote is missing or unclear, the draft and the invoice hold with the missing field named, and no amount is estimated

Duplicate keys: one identity per record

Search the list before a record is added. Blank values never group. Two records with a blank certificate number, plate, reference or token stay separate until a real value is entered on each record.

Booking

One booking per reference code per workspace, and one booking per public token per workspace. A public token is system entered, is never blank, and is never reused. Two bookings with the same reference code or token are duplicates of one booking. Keep the second in Quote and out of the day board until staff confirm with the booker or passenger which booking is the real run.

Customer

Group only when the normalized name matches and the normalized phone matches or the normalized email matches. Normalize a name by trimming, collapsing spaces and comparing in lower case. Normalize a phone by digits only, with 10 digits compared as 1 plus those digits, and an extension kept separate. Normalize an email by trimming, removing spaces and comparing in lower case. A shared phone or a shared inbox alone never groups records.

Chauffeur

Group only when the normalized certificate number matches, or the normalized name matches and the normalized phone or email matches. Normalize a certificate number by trimming, upper case, and removing spaces and hyphens. A matching certificate is stronger than a matching name. Keep the record linked to a sign-in account over an unlinked record.

Vehicle

Group only when the normalized plate matches or the normalized permit number matches, by trimming, upper case, and removing spaces and hyphens. Colour and type never group vehicles, since several vehicles can share colour and type with different plates. Keep the active vehicle with permit and inspection valid for the pickup date over a retired record.

Referential constraints

Every link below must open to a real record in the same workspace, with the same workspace number on the child and the parent. A link that fails this table is an orphan. Never change the workspace on a record to make a link match, never delete a parent to clear a link, and never cascade a delete from a parent to a booking, check, draft, issue or invoice.

Booking links

  • bookings customer link points to one customer record in the same workspace
  • bookings chauffeur link, when present, points to one chauffeur record in the same workspace
  • bookings vehicle link, when present, points to one vehicle record in the same workspace
  • bookings reference code and public token are unique per workspace, as above

Check, service, draft, issue and invoice links

  • daily checks vehicle link points to one vehicle record, and the check date is not blank
  • service logs vehicle link points to one vehicle record, and the item is one of the 14 livery items for that workspace
  • message drafts booking link points to one booking record in the same workspace, with one draft per booking per kind at a time
  • issues booking link and invoices booking and customer links point to records in the same workspace, and an invoice is issued only from Complete bookings

File links

  • A file reference, when supplied, names a real record in the same workspace
  • A file for a certificate, permit, inspection or insurance card stays listed only on the record it proves, and never proves another chauffeur or vehicle

When a constraint fails

  • Hold the dependent step: a booking with no confirmed customer is not confirmed, a run with no chauffeur or no Ready vehicle is not dispatched, and a draft with no booking is not approved or sent
  • Keep the record, flag the reason in words on the row, and keep it out of the day board, reports and invoices
  • Add a real record first, with details confirmed by the customer, chauffeur or shop, then link it. Never create a placeholder customer, chauffeur or vehicle to close a gap

Cleanup runbook

Work through these steps in order, in one workspace at a time. Confirm table and column names against migrations/0002_app.sql for the build before running a query. The queries change no record.

  1. Run the completeness audit

    List Confirmed runs with a blank passenger name, a passenger phone under 10 digits, passengers outside 1 to 7, no vehicle link, no chauffeur link, or no pickup time. Example, capped at 200 rows: SELECT id, reference_code FROM bookings WHERE tenant_id = :workspace AND status NOT IN ('Quote','Cancelled') AND (pickup_at IS NULL OR vehicle_id IS NULL OR chauffeur_id IS NULL OR TRIM(passenger_name) = '') LIMIT 200;

  2. Run the date audit

    List runs where call time does not equal pickup time minus the saved lead hours, where a daily check date for an assigned vehicle does not equal pickup date, or where pickup time is in the past and status is not Complete. Quarantine each row in Quote until pickup time is corrected to a future date and time on the booking.

  3. Run the orphan audit

    List bookings whose customer, chauffeur or vehicle link finds no record in the same workspace, and daily checks, service logs, drafts, issues and invoices whose parent link finds no record. Use a left join on id and tenant_id, as in the data quality guide. Any row is held out of dispatch, reports and invoices.

  4. Run the duplicate audit

    Group chauffeurs by normalized certificate number, vehicles by normalized plate and by normalized permit number, and bookings by reference code and by public token, with blanks excluded. Any group with more than one active record is a duplicate group to merge under the merge guide, never to delete.

  5. Repair from a real record, then recount

    Contact the booker or passenger for passenger data, the chauffeur for certificate data, and the shop for vehicle data. Correct the named record first, then re-read the quote, call time, status and flags. Count bookings, files, checks, service entries and role links on the keeper before the move and again after. The keeper count after must equal keeper before plus duplicate before for each category.

  6. Quarantine what cannot be repaired

    Keep the record flagged in words, in Quote status where the booking is not yet confirmed, with drafts held and no invoice issued. List it for the owner or manager to recover. A quarantined run is never counted as covered and never counted as a completed trip.

  7. Re-run every audit to zero

    Zero rows for the completeness, date, orphan and duplicate audits is the pass mark for one workspace. A result of 200 rows means the cap was reached. Quarantine those rows and re-run the same query with the same workspace filter until fewer than 200 rows return.

Acceptance checks before you ship

Run each check with one booking that is missing a passenger detail, one missing a vehicle, and one with a mismatched check date.

  • A Confirmed run with a blank passenger name or a phone under 10 digits fails the gate, stays in Quote, and receives no chauffeur details draft
  • A Confirmed run with no vehicle link, a check date that does not equal pickup date, or an expired permit or inspection fails the gate and is never assigned
  • A run where call time does not equal pickup time minus lead hours fails the date audit and is corrected on the booking before assignment
  • Two bookings with the same reference code or public token, two chauffeurs with the same normalized certificate, and two vehicles with the same normalized plate each group as duplicates and are merged, never deleted
  • Every audit query returns zero rows for one workspace after cleanup, and a 200 row result is treated as more work to quarantine, not as a clean result
  • After any repair, the booking, assigned chauffeur, assigned vehicle, daily check for the pickup date and flag on the row are re-read before assignment, and the draft that is approved matches the current record

Hold the run until the record is complete

Run the gate, repair the named record, and re-run the audits to zero before the run is dispatched.