DO $$
BEGIN
  IF to_regclass('public.app_change_logs') IS NULL THEN
    RAISE EXCEPTION 'missing table: app_change_logs';
  END IF;
  IF to_regclass('public.app_status_change_requests') IS NULL THEN
    RAISE EXCEPTION 'missing table: app_status_change_requests';
  END IF;

  IF NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'public' AND table_name = 'apps' AND column_name = 'app_type'
  ) THEN
    RAISE EXCEPTION 'apps.app_type missing';
  END IF;

  IF NOT EXISTS (SELECT 1 FROM permissions WHERE code = 'iam:app:read') THEN
    RAISE EXCEPTION 'missing seed permission iam:app:read';
  END IF;
  IF NOT EXISTS (SELECT 1 FROM permissions WHERE code = 'iam:app:approve') THEN
    RAISE EXCEPTION 'missing seed permission iam:app:approve';
  END IF;
END $$;

