diff --git a/apps/api/prisma/migrations/20261007190000_customer_city_name_raw/migration.sql b/apps/api/prisma/migrations/20261007190000_customer_city_name_raw/migration.sql new file mode 100644 index 0000000..9ed73ec --- /dev/null +++ b/apps/api/prisma/migrations/20261007190000_customer_city_name_raw/migration.sql @@ -0,0 +1,22 @@ +-- ============================================================================ +-- Customer.cityNameRaw — PURELY ADDITIVE. +-- +-- Owner ruling 2026-10-07 (docs/DATA-MIGRATION-MAP.md §5.9): keep the city a +-- customer typed at sign-up verbatim, and set cityId only on an exact match. +-- +-- Legacy `customers.new_city` is free text (all 172 live values are names, 0 +-- are ids). The legacy city table has only 15 rows, so 43 of those names match +-- no known city at all, and only ~72 match one of the 15 after ي/ك +-- normalisation. Dropping the text would lose where those customers are. +-- +-- Legacy sign-up also forced city_id = 5 (تهران) on every new customer +-- (Major/CustomerController.php:21); 91 of the 92 customers with both values +-- carry that forced Tehran. For them the typed name is the truth. +-- +-- D15: idempotent, runs under both migration ledgers. +-- ============================================================================ + +ALTER TABLE "Customer" ADD COLUMN IF NOT EXISTS "cityNameRaw" TEXT; + +COMMENT ON COLUMN "Customer"."cityNameRaw" IS + 'Legacy customers.new_city — city name as typed at sign-up, kept verbatim. cityId is set too only on an exact (ي/ك-normalised) match; legacy forced city_id=5 (Tehran) on sign-up, so prefer this text over that cityId.'; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index 91e7eb4..3254b59 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -390,6 +390,16 @@ model Customer { cityId String? city City? @relation(fields: [cityId], references: [id]) + /// Legacy customers.new_city — the city name exactly as the customer typed it + /// at app sign-up (Major/CustomerController.php:36). Kept verbatim because + /// the legacy city table has only 15 rows, so the typed name is often the only + /// record of where the customer is (172 customers; 43 match no known city). + /// cityId is set alongside it only on an exact, ي/ك-normalised name match. + /// Legacy sign-up also forced city_id = 5 (Tehran) on everyone + /// (Major/CustomerController.php:21), so for those rows the typed name, not + /// cityId, is the truth. Owner ruling 2026-10-07: keep both. + cityNameRaw String? + /// Legacy Customer.type — distinguishes بنکدار from مغازه دار, which the /// BankerList / ShopkeeperList screens filter on. kind CustomerKind @default(APP_SHOPKEEPER)