Files
CRM-LeadRadar/apps/api/drizzle/0001_left_lady_deathstrike.sql
T
yuriandClaude Opus 5.5 9749da5ae7 Lead Radar: исходный код
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-25 23:11:04 +04:00

10 lines
554 B
SQL

ALTER TABLE "events" ADD COLUMN "status_id" integer;--> statement-breakpoint
UPDATE "events" e SET "status_id" = s."id"
FROM "pipeline_statuses" s
WHERE e."type" IN ('status', 'deal') AND s."company_id" = e."company_id" AND s."name" = e."new_value"
AND s."pipeline" = CASE WHEN e."lead_id" IS NOT NULL THEN 'object' ELSE 'client' END;
--> statement-breakpoint
UPDATE "events" e SET "status_id" = s."id"
FROM "pipeline_statuses" s
WHERE e."type" = 'blacklisted' AND s."company_id" = e."company_id" AND s."pipeline" = 'object' AND s."code" = 'rejected';