Skip to content

Phone numbers that differ for one person

Since migration 20261002120000_one_phone_per_person.sql, a person's phone is one number (ACC-076): the login (User.phone), the partner record (Agent.phone) and the customer record (Customer.phone) of the same person are kept in step by the database.

Records saved before that migration may still hold different numbers. The migration does not pick one: nobody can tell which is right. It only fills a blank side. This page is how the office finds and fixes the rest.

What the migration did on its own

phone_fill_blanks() ran once:

  • a login with no phone took the number of its partner or customer record, when those records hold one number between them (never for a staff login);
  • a partner or customer record with no phone took its login's number.

Each filled record has an audit row with metadata.reason = phone_sync backfill (blank filled). Running the function again fills nothing.

List the differences

In the Supabase SQL editor (service role — the function cannot be called from the browser):

select * from public.phone_mismatches();

One row per login and record whose numbers differ on the last ten digits. A number written in another way (09906272405 against +91 99062 72405) is the same number and is not listed.

Column Meaning
user_id, login_name the login
login_is_staff a staff login — its number is changed on the login only
record partner or customer
record_id, record_code, record_name the record (BP-… or CU-…)
login_phone_last4, record_phone_last4 the last four digits of each number — never the number

The query reads only. It changes nothing.

Fix one

Ask the person, or check the latest booking or WhatsApp thread, which number is current. Then change it once, on the screen the office normally uses:

  • a partner — the partner record, Edit (partners.edit);
  • a customer — the customer's Edit (customers.edit);
  • a staff login — the employee record, Edit profile (admin.users.edit), or the person on My profile.

The database copies the new number to the other records of the same person and writes an audit row on each, with metadata.reason = phone_sync from …. Run the list again: the row is gone.

A staff login whose customer or partner record holds another number is fixed on the login: the login's number flows to the record, never the other way.

Not done here

  • No screen lists the differences; this runbook is the way.
  • A partner's contacts (PartnerContact) are separate people and are never compared or synced.