-- Add RebreakMagic DNS-Device-Binding fields to UserDevice table

ALTER TABLE "rebreak"."user_devices"
  ADD COLUMN IF NOT EXISTS "magic_dns_token" TEXT;

ALTER TABLE "rebreak"."user_devices"
  ADD COLUMN IF NOT EXISTS "magic_enrolled_at" TIMESTAMP(3);

ALTER TABLE "rebreak"."user_devices"
  ADD COLUMN IF NOT EXISTS "magic_revoked_at" TIMESTAMP(3);

ALTER TABLE "rebreak"."user_devices"
  ADD COLUMN IF NOT EXISTS "magic_hostname" TEXT;

-- Create unique index on magic_dns_token (NULL values are ignored in unique constraints)
CREATE UNIQUE INDEX IF NOT EXISTS "user_devices_magic_dns_token_key"
  ON "rebreak"."user_devices"("magic_dns_token");
