ALTER TABLE "router_v1.11"."merkle_paths" DROP CONSTRAINT "merkle_paths_offer_hash_offers_hash_fk";
--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" DROP CONSTRAINT "offers_callbacks_offer_hash_offers_hash_fk";
--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" DROP CONSTRAINT "validations_offer_hash_offers_hash_fk";
--> statement-breakpoint
ALTER TABLE "router_v1.11"."merkle_paths" ADD COLUMN "obligation_id" varchar(66);--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" ADD COLUMN "obligation_id" varchar(66);--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" ADD COLUMN "obligation_id" varchar(66);--> statement-breakpoint
--> statement-breakpoint
UPDATE "router_v1.11"."merkle_paths" AS "mp"
SET "obligation_id" = "offers"."obligation_id"
FROM "router_v1.11"."offers"
WHERE "mp"."offer_hash" = "offers"."hash";--> statement-breakpoint
UPDATE "router_v1.11"."offers_callbacks" AS "oc"
SET "obligation_id" = "offers"."obligation_id"
FROM "router_v1.11"."offers"
WHERE "oc"."offer_hash" = "offers"."hash";--> statement-breakpoint
UPDATE "router_v1.11"."validations" AS "v"
SET "obligation_id" = "offers"."obligation_id"
FROM "router_v1.11"."offers"
WHERE "v"."offer_hash" = "offers"."hash";--> statement-breakpoint
ALTER TABLE "router_v1.11"."merkle_paths" ALTER COLUMN "obligation_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" ALTER COLUMN "obligation_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" ALTER COLUMN "obligation_id" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "router_v1.11"."merkle_paths" DROP CONSTRAINT IF EXISTS "merkle_paths_pkey";--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers" DROP CONSTRAINT IF EXISTS "offers_pkey";--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" DROP CONSTRAINT IF EXISTS "validations_pkey";--> statement-breakpoint
ALTER TABLE "router_v1.11"."merkle_paths" ADD CONSTRAINT "merkle_paths_pk" PRIMARY KEY("offer_hash","obligation_id");--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers" ADD CONSTRAINT "offers_pk" PRIMARY KEY("hash","obligation_id");--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" ADD CONSTRAINT "validations_pk" PRIMARY KEY("offer_hash","obligation_id");--> statement-breakpoint
ALTER TABLE "router_v1.11"."merkle_paths" ADD CONSTRAINT "merkle_paths_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.11"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" ADD CONSTRAINT "offers_callbacks_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.11"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.11"."validations" ADD CONSTRAINT "validations_offer_fk" FOREIGN KEY ("offer_hash","obligation_id") REFERENCES "router_v1.11"."offers"("hash","obligation_id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" DROP CONSTRAINT "offers_callbacks_pk";
--> statement-breakpoint
ALTER TABLE "router_v1.11"."offers_callbacks" ADD CONSTRAINT "offers_callbacks_pk" PRIMARY KEY("offer_hash","obligation_id","callback_id");
