-- AlterTable: drop NOT NULL on payment_id
ALTER TABLE "payment_disputes" ALTER COLUMN "payment_id" DROP NOT NULL;

-- AlterTable: change FK onDelete from Cascade to SetNull
ALTER TABLE "payment_disputes" DROP CONSTRAINT "payment_disputes_payment_id_fkey";
ALTER TABLE "payment_disputes" ADD CONSTRAINT "payment_disputes_payment_id_fkey"
  FOREIGN KEY ("payment_id") REFERENCES "payments"("id")
  ON DELETE SET NULL ON UPDATE CASCADE;

-- AlterTable: add paypal_sale_id for back-linking
ALTER TABLE "payment_disputes" ADD COLUMN "paypal_sale_id" VARCHAR(100);

-- CreateIndex
CREATE INDEX "payment_disputes_paypal_sale_id_idx" ON "payment_disputes"("paypal_sale_id");
