CREATE EXTENSION IF NOT EXISTS pgcrypto;

DO $$
BEGIN
  IF to_regclass('public.models') IS NULL THEN
    RAISE NOTICE 'Table models does not exist yet. Run init and prior migrations first.';
  ELSE
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='models' AND column_name='manager_phone') THEN
      EXECUTE 'ALTER TABLE models ADD COLUMN manager_phone TEXT';
    END IF;
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='models' AND column_name='manager_whatsapp') THEN
      EXECUTE 'ALTER TABLE models ADD COLUMN manager_whatsapp TEXT';
    END IF;
  END IF;
END$$;
