ALTER TYPE "UserStatus" ADD VALUE IF NOT EXISTS 'invited';

ALTER TABLE "users"
  ALTER COLUMN "password_hash" DROP NOT NULL,
  ALTER COLUMN "status" SET DEFAULT 'invited',
  ADD COLUMN IF NOT EXISTS "invite_token_hash" TEXT,
  ADD COLUMN IF NOT EXISTS "invite_token_expires_at" TIMESTAMP(3),
  ADD COLUMN IF NOT EXISTS "email_verified_at" TIMESTAMP(3),
  ADD COLUMN IF NOT EXISTS "last_login_at" TIMESTAMP(3);

UPDATE "users"
SET "status" = 'active'
WHERE "status" IS NULL OR "status"::text = 'active';

CREATE INDEX IF NOT EXISTS "users_invite_token_hash_idx" ON "users"("invite_token_hash");
