BEGIN;

DO $$
DECLARE
  rec record;
BEGIN
  FOR rec IN
    SELECT conname
    FROM pg_constraint
    WHERE contype = 'p' AND conrelid = 'mtm_ledger'::regclass
  LOOP
    EXECUTE format('ALTER TABLE mtm_ledger DROP CONSTRAINT %I', rec.conname);
  END LOOP;
  ALTER TABLE mtm_ledger
    ADD CONSTRAINT mtm_ledger_pkey PRIMARY KEY (user_id, run_id, logical_time);
END $$;

DO $$
DECLARE
  rec record;
BEGIN
  FOR rec IN
    SELECT conname
    FROM pg_constraint
    WHERE contype = 'p' AND conrelid = 'paper_equity_curve'::regclass
  LOOP
    EXECUTE format('ALTER TABLE paper_equity_curve DROP CONSTRAINT %I', rec.conname);
  END LOOP;
  ALTER TABLE paper_equity_curve
    ADD CONSTRAINT paper_equity_curve_pkey PRIMARY KEY (user_id, run_id, logical_time);
END $$;

COMMIT;
