Keep previous import source and code when a person is re-imported from another source
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "previousImportSource" TEXT;
|
||||
ALTER TABLE "Person" ADD COLUMN IF NOT EXISTS "previousSourceRef" TEXT;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "Person_organizationId_previousSourceRef_idx" ON "Person"("organizationId", "previousSourceRef");
|
||||
|
||||
-- اشخاصی که قبلاً از دیدار آمدهاند و بعد با تهحساب بازنویسی شدهاند: کد دیدار را بهعنوان کد قبلی بازیابی کن
|
||||
UPDATE "Person"
|
||||
SET "previousImportSource" = 'didar',
|
||||
"previousSourceRef" = TRIM("customFields"->>'didarId')
|
||||
WHERE "importSource" = 'tahesab'
|
||||
AND "previousSourceRef" IS NULL
|
||||
AND "customFields" IS NOT NULL
|
||||
AND jsonb_typeof("customFields") = 'object'
|
||||
AND COALESCE(TRIM("customFields"->>'didarId'), '') <> '';
|
||||
@@ -441,6 +441,9 @@ model Person {
|
||||
importSource String @default("manual")
|
||||
/// شناسه در مبدأ (کد دیدار، کد مشتری تهحساب، …)
|
||||
sourceRef String?
|
||||
/// منبع و کد قبلی وقتی شخص از منبع دیگری دوباره وارد شده (مثلاً دیدار قبل از تهحساب)
|
||||
previousImportSource String?
|
||||
previousSourceRef String?
|
||||
email String?
|
||||
phone String?
|
||||
mobile String?
|
||||
@@ -488,6 +491,7 @@ model Person {
|
||||
@@index([organizationId, lastName, firstName])
|
||||
@@index([organizationId, importSource])
|
||||
@@index([organizationId, sourceRef])
|
||||
@@index([organizationId, previousSourceRef])
|
||||
@@index([organizationId, loyaltyPoints])
|
||||
@@index([companyId])
|
||||
@@index([ownerId])
|
||||
|
||||
Reference in New Issue
Block a user