Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
10 lines
554 B
SQL
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';
|