ALTER TABLE investment_opportunities
  ADD COLUMN IF NOT EXISTS funding_model text NOT NULL DEFAULT 'CROWD';

UPDATE investment_opportunities
SET funding_model = 'CROWD'
WHERE funding_model IS NULL OR funding_model NOT IN ('CROWD', 'NON_CROWD');

DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'investment_opportunities_funding_model_check'
  ) THEN
    ALTER TABLE investment_opportunities
      ADD CONSTRAINT investment_opportunities_funding_model_check
      CHECK (funding_model IN ('CROWD', 'NON_CROWD'));
  END IF;
END $$;
