-- Add phone column to mobile_users table
ALTER TABLE mobile_users ADD COLUMN phone TEXT;

-- Migrate phone from metadata to column for existing users
UPDATE mobile_users 
SET phone = json_extract(metadata, '$.phone')
WHERE metadata IS NOT NULL 
  AND json_extract(metadata, '$.phone') IS NOT NULL;

-- Create index for phone since it may be used for lookup
CREATE INDEX IF NOT EXISTS idx_mobile_users_phone ON mobile_users(phone);
