-- ============================================================================
-- Dabil — OAuth support migration
-- Run ONCE against the `yqpqsjjj_dabil2` database (phpMyAdmin > SQL, or CLI).
-- Adds the columns social sign-in needs. Safe: only ADDs, never drops.
-- ============================================================================

ALTER TABLE `users`
  ADD COLUMN `auth_provider`  VARCHAR(20)  NOT NULL DEFAULT 'local' AFTER `password`,
  ADD COLUMN `provider_uid`   VARCHAR(255) DEFAULT NULL              AFTER `auth_provider`,
  ADD COLUMN `email_verified` TINYINT(1)   NOT NULL DEFAULT 0        AFTER `provider_uid`;

-- Speeds up "find this social account" lookups.
ALTER TABLE `users`
  ADD INDEX `idx_auth_provider` (`auth_provider`, `provider_uid`);

-- NOTE: `password` is left NOT NULL. Social accounts are created with a random,
-- unguessable hash (they can never be logged into with a password), so no
-- schema change to `password` is required.
