CREATE TABLE "client_merge_candidates" ( "id" text PRIMARY KEY NOT NULL, "port_id" text NOT NULL, "client_a_id" text NOT NULL, "client_b_id" text NOT NULL, "score" integer NOT NULL, "reasons" jsonb NOT NULL, "status" text DEFAULT 'pending' NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "resolved_at" timestamp with time zone, "resolved_by" text ); --> statement-breakpoint CREATE TABLE "migration_source_links" ( "id" text PRIMARY KEY NOT NULL, "source_system" text NOT NULL, "source_id" text NOT NULL, "target_entity_type" text NOT NULL, "target_entity_id" text NOT NULL, "applied_id" text NOT NULL, "applied_by" text, "applied_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_port_id_ports_id_fk" FOREIGN KEY ("port_id") REFERENCES "public"."ports"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_client_a_id_clients_id_fk" FOREIGN KEY ("client_a_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "client_merge_candidates" ADD CONSTRAINT "client_merge_candidates_client_b_id_clients_id_fk" FOREIGN KEY ("client_b_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint CREATE INDEX "idx_cmc_port_status" ON "client_merge_candidates" USING btree ("port_id","status");--> statement-breakpoint CREATE UNIQUE INDEX "idx_cmc_pair" ON "client_merge_candidates" USING btree ("port_id","client_a_id","client_b_id");--> statement-breakpoint CREATE UNIQUE INDEX "idx_msl_source_target" ON "migration_source_links" USING btree ("source_system","source_id","target_entity_type");