-- AlterTable ALTER TABLE "users" ADD COLUMN "invite_code" VARCHAR(16); -- Backfill existing admins and agents with deterministic unique codes UPDATE "users" SET "invite_code" = UPPER(SUBSTR(MD5("id"::text || ':invite'), 1, 8)) WHERE "user_type" IN ('ADMIN', 'AGENT') AND "invite_code" IS NULL; -- CreateIndex CREATE UNIQUE INDEX "users_invite_code_key" ON "users"("invite_code");