-- Link migrated portfolios / media to legacy WillaEngine ids
ALTER TABLE portfolios
  ADD COLUMN IF NOT EXISTS old_id BIGINT;

CREATE UNIQUE INDEX IF NOT EXISTS portfolios_business_old_id_unique
  ON portfolios (business_id, old_id)
  WHERE old_id IS NOT NULL;

ALTER TABLE media
  ADD COLUMN IF NOT EXISTS old_id BIGINT;

CREATE UNIQUE INDEX IF NOT EXISTS media_business_old_id_unique
  ON media (business_id, old_id)
  WHERE old_id IS NOT NULL;
