Track person import source and previous names; add source report and edit UX.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "previousFirstName" TEXT;
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "previousLastName" TEXT;
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "importSource" TEXT NOT NULL DEFAULT 'manual';
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "sourceRef" TEXT;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX IF NOT EXISTS "Person_organizationId_importSource_idx" ON "Person"("organizationId", "importSource");
|
||||
CREATE INDEX IF NOT EXISTS "Person_organizationId_sourceRef_idx" ON "Person"("organizationId", "sourceRef");
|
||||
|
||||
-- Backfill from legacy customFields / notes
|
||||
UPDATE "Person"
|
||||
SET
|
||||
"importSource" = 'didar',
|
||||
"sourceRef" = COALESCE(NULLIF(BTRIM("sourceRef"), ''), NULLIF(BTRIM("customFields"->>'didarId'), ''))
|
||||
WHERE COALESCE(BTRIM("customFields"->>'didarId'), '') <> '';
|
||||
|
||||
UPDATE "Person"
|
||||
SET "importSource" = 'tahesab'
|
||||
WHERE "importSource" = 'manual'
|
||||
AND notes ILIKE '%تهحساب%';
|
||||
|
||||
UPDATE "Person"
|
||||
SET "importSource" = 'excel'
|
||||
WHERE "importSource" = 'manual'
|
||||
AND COALESCE(BTRIM("customFields"->>'customerCode'), '') <> ''
|
||||
AND COALESCE(BTRIM("customFields"->>'didarId'), '') = '';
|
||||
@@ -433,6 +433,13 @@ model Person {
|
||||
company Company? @relation(fields: [companyId], references: [id], onDelete: SetNull)
|
||||
firstName String
|
||||
lastName String
|
||||
/// نام قبل از همگامسازی مبدأ (مثلاً تهحساب)
|
||||
previousFirstName String?
|
||||
previousLastName String?
|
||||
/// منبع ورود: manual | tahesab | didar | excel | phone | lead_form | other
|
||||
importSource String @default("manual")
|
||||
/// شناسه در مبدأ (کد دیدار، کد مشتری تهحساب، …)
|
||||
sourceRef String?
|
||||
email String?
|
||||
phone String?
|
||||
mobile String?
|
||||
@@ -478,6 +485,8 @@ model Person {
|
||||
@@index([organizationId, email])
|
||||
@@index([organizationId, mobile])
|
||||
@@index([organizationId, lastName, firstName])
|
||||
@@index([organizationId, importSource])
|
||||
@@index([organizationId, sourceRef])
|
||||
@@index([organizationId, loyaltyPoints])
|
||||
@@index([companyId])
|
||||
@@index([ownerId])
|
||||
|
||||
Reference in New Issue
Block a user