-- Migration to add secure password hashing support
-- This adds a password_hash column and sets up for secure authentication

-- Add password_hash column
ALTER TABLE `user` ADD COLUMN `password_hash` VARCHAR(255) AFTER `password`;

-- Add last_login timestamp
ALTER TABLE `user` ADD COLUMN `last_login` TIMESTAMP NULL AFTER `doc`;

-- Create index on email for faster lookups
CREATE INDEX idx_user_email ON `user`(`email`);

-- Create index on password_hash for authentication
CREATE INDEX idx_user_password_hash ON `user`(`password_hash`);

-- Update existing users with hashed passwords (this will be done gradually during login)
-- Note: Existing plain text passwords will be migrated to hashed passwords when users log in

-- Add login_type column to distinguish between regular and Google logins
ALTER TABLE `user` ADD COLUMN `login_type` ENUM('regular', 'google') DEFAULT 'regular' AFTER `profile_img_url`;
