-- ==========================================================
-- SaniBook Auth Enhancement Migration
-- Date: Feb 19, 2026
-- Purpose: Add missing profile columns + profile_completed flag
-- ==========================================================

-- Ensure county column exists (may be missing on live)
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `county` VARCHAR(100) DEFAULT NULL;

-- Add profile_completed column (0 = incomplete, 1 = complete)
-- Existing users are assumed complete; new Google sign-ups start at 0
ALTER TABLE `users` ADD COLUMN IF NOT EXISTS `profile_completed` TINYINT(1) NOT NULL DEFAULT 1;

-- Mark existing Google-created accounts without phone as incomplete
UPDATE `users`
SET `profile_completed` = 0
WHERE `google_id` IS NOT NULL
  AND (`phone` IS NULL OR `phone` = '')
  AND `role` != 'admin';

-- ==========================================================
-- SCRIPT END
-- ==========================================================
