-- Migration: Ajouter la colonne status à la table users
-- Date: 2026-01-14

-- Ajouter la colonne status
ALTER TABLE `users` ADD COLUMN `status` ENUM('active', 'inactive', 'blocked', 'pending') NOT NULL DEFAULT 'active' AFTER `role`;

-- Ajouter la colonne last_login_ip
ALTER TABLE `users` ADD COLUMN `last_login_ip` VARCHAR(45) NULL AFTER `last_login_at`;

-- Ajouter la colonne must_change_password
ALTER TABLE `users` ADD COLUMN `must_change_password` TINYINT(1) NOT NULL DEFAULT 0 AFTER `remember_token`;

-- Mettre à jour status en fonction de is_active existant
UPDATE `users` SET `status` = CASE WHEN `is_active` = 1 THEN 'active' ELSE 'inactive' END;

-- Ajouter index sur status
ALTER TABLE `users` ADD INDEX `users_status_index` (`status`);
