-- Çok fazla yanlış girişte hesap kilidi (admin_login.php).
-- Bir kez çalıştırın.

USE faunamix;

SET @fc := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_users' AND COLUMN_NAME = 'login_failed_count'
);
SET @sql_fc := IF(@fc = 0,
  'ALTER TABLE admin_users ADD COLUMN login_failed_count INT UNSIGNED NOT NULL DEFAULT 0 AFTER password_hash',
  'SELECT 1');
PREPARE stmt FROM @sql_fc; EXECUTE stmt; DEALLOCATE PREPARE stmt;

SET @lk := (
  SELECT COUNT(*) FROM information_schema.COLUMNS
  WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'admin_users' AND COLUMN_NAME = 'login_locked_until'
);
SET @sql_lk := IF(@lk = 0,
  'ALTER TABLE admin_users ADD COLUMN login_locked_until DATETIME NULL AFTER login_failed_count',
  'SELECT 1');
PREPARE stmt FROM @sql_lk; EXECUTE stmt; DEALLOCATE PREPARE stmt;
