ALTER TABLE "public"."invitations" ADD COLUMN IF NOT EXISTS personal_code text;

DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'accounts_personal_code_unique'
  ) THEN
    ALTER TABLE public.accounts
    ADD CONSTRAINT accounts_personal_code_unique UNIQUE (personal_code);
  END IF;
END$$;

ALTER TABLE public.invitations
ALTER COLUMN personal_code TYPE text;

DO $$
BEGIN
  IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'invitations_personal_code_unique'
  ) THEN
    ALTER TABLE public.invitations
    ADD CONSTRAINT invitations_personal_code_unique UNIQUE (personal_code);
  END IF;
END$$;

