From 024713e3aca16b007dce9ff74dd66966c9d7bdd9 Mon Sep 17 00:00:00 2001 From: Dotta Date: Wed, 8 Jul 2026 07:21:50 +0000 Subject: [PATCH] Address Greptile migration backfill feedback Co-Authored-By: Paperclip --- .../migrations/0113_pipeline_foundation.sql | 18 +++++++++++++----- .../0121_pipeline_automation_retry_effects.sql | 10 ++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/db/src/migrations/0113_pipeline_foundation.sql b/packages/db/src/migrations/0113_pipeline_foundation.sql index 96d9b4868eb..26fcea2f072 100644 --- a/packages/db/src/migrations/0113_pipeline_foundation.sql +++ b/packages/db/src/migrations/0113_pipeline_foundation.sql @@ -277,9 +277,11 @@ WHERE "pipeline_cases"."id" = unique_candidates."id" WHERE "existing_cases"."pipeline_id" = "pipeline_cases"."pipeline_id" AND "existing_cases"."case_key" = unique_candidates."candidate" );--> statement-breakpoint -UPDATE "pipeline_cases" -SET "case_key" = "id"::text -WHERE "case_key" IS NULL;--> statement-breakpoint +DO $$ BEGIN + IF EXISTS (SELECT 1 FROM "pipeline_cases" WHERE "case_key" IS NULL) THEN + RAISE EXCEPTION 'Cannot backfill pipeline_cases.case_key for existing rows without fields key or origin issue identifier'; + END IF; +END $$;--> statement-breakpoint ALTER TABLE "pipeline_cases" ALTER COLUMN "case_key" SET NOT NULL;--> statement-breakpoint ALTER TABLE "pipeline_cases" ADD COLUMN IF NOT EXISTS "parent_case_id" uuid;--> statement-breakpoint ALTER TABLE "pipeline_cases" ADD COLUMN IF NOT EXISTS "lease_expires_at" timestamp with time zone;--> statement-breakpoint @@ -338,8 +340,8 @@ UPDATE "pipeline_case_events" SET "payload" = '{}'::jsonb WHERE "payload" IS NULL;--> statement-breakpoint ALTER TABLE "pipeline_case_events" ALTER COLUMN "payload" SET NOT NULL;--> statement-breakpoint -ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "updated_at" timestamp with time zone DEFAULT now();--> statement-breakpoint -ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "created_at" timestamp with time zone DEFAULT now();--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "updated_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "created_at" timestamp with time zone;--> statement-breakpoint UPDATE "pipeline_case_events" SET "created_at" = coalesce( "pipeline_case_events"."updated_at", @@ -350,6 +352,12 @@ SET "created_at" = coalesce( FROM "pipeline_cases" WHERE "pipeline_case_events"."case_id" = "pipeline_cases"."id" AND "pipeline_case_events"."created_at" IS NULL;--> statement-breakpoint +UPDATE "pipeline_case_events" +SET "updated_at" = "created_at" +WHERE "updated_at" IS NULL;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "updated_at" SET DEFAULT now();--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "updated_at" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "created_at" SET DEFAULT now();--> statement-breakpoint ALTER TABLE "pipeline_case_events" ALTER COLUMN "created_at" SET NOT NULL;--> statement-breakpoint ALTER TABLE "pipeline_cases" ADD COLUMN IF NOT EXISTS "lease_agent_id" uuid;--> statement-breakpoint ALTER TABLE "pipeline_cases" ADD COLUMN IF NOT EXISTS "created_by_agent_id" uuid;--> statement-breakpoint diff --git a/packages/db/src/migrations/0121_pipeline_automation_retry_effects.sql b/packages/db/src/migrations/0121_pipeline_automation_retry_effects.sql index fe0bff56572..c80a25e3db3 100644 --- a/packages/db/src/migrations/0121_pipeline_automation_retry_effects.sql +++ b/packages/db/src/migrations/0121_pipeline_automation_retry_effects.sql @@ -29,8 +29,8 @@ UPDATE "pipeline_case_events" SET "payload" = '{}'::jsonb WHERE "payload" IS NULL;--> statement-breakpoint ALTER TABLE "pipeline_case_events" ALTER COLUMN "payload" SET NOT NULL;--> statement-breakpoint -ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "updated_at" timestamp with time zone DEFAULT now();--> statement-breakpoint -ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "created_at" timestamp with time zone DEFAULT now();--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "updated_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ADD COLUMN IF NOT EXISTS "created_at" timestamp with time zone;--> statement-breakpoint UPDATE "pipeline_case_events" SET "created_at" = coalesce( "pipeline_case_events"."updated_at", @@ -41,6 +41,12 @@ SET "created_at" = coalesce( FROM "pipeline_cases" WHERE "pipeline_case_events"."case_id" = "pipeline_cases"."id" AND "pipeline_case_events"."created_at" IS NULL;--> statement-breakpoint +UPDATE "pipeline_case_events" +SET "updated_at" = "created_at" +WHERE "updated_at" IS NULL;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "updated_at" SET DEFAULT now();--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "updated_at" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "pipeline_case_events" ALTER COLUMN "created_at" SET DEFAULT now();--> statement-breakpoint ALTER TABLE "pipeline_case_events" ALTER COLUMN "created_at" SET NOT NULL;--> statement-breakpoint DROP INDEX IF EXISTS "pipeline_cases_parent_request_key_uq";--> statement-breakpoint CREATE UNIQUE INDEX IF NOT EXISTS "pipeline_cases_parent_request_key_uq" ON "pipeline_cases" USING btree ("parent_case_id","request_key") WHERE "pipeline_cases"."request_key" is not null and "pipeline_cases"."retired_at" is null;--> statement-breakpoint