-- Expand users.mobile for AES-256-GCM ciphertext and add blind index for lookup.
-- Run once on deployed DB: psql "$DATABASE_URL" -f scripts/patch-users-mobile-encryption.sql

ALTER TABLE users
  ALTER COLUMN mobile TYPE VARCHAR(255);

ALTER TABLE users
  ADD COLUMN IF NOT EXISTS mobile_index VARCHAR(64);

CREATE INDEX IF NOT EXISTS idx_users_mobile_index
  ON users (mobile_index)
  WHERE deleted_at IS NULL AND mobile_index IS NOT NULL;
