-- Database Schema Update for Auto-Logout Settings (Fixed Version)
-- Add failed login attempts and auto logout settings using key-value format

-- Add failed login tracking columns to users table
ALTER TABLE users ADD COLUMN IF NOT EXISTS failed_login_attempts INT DEFAULT 0 AFTER last_activity;
ALTER TABLE users ADD COLUMN IF NOT EXISTS last_failed_login DATETIME NULL AFTER failed_login_attempts;

-- Add auto logout settings to settings table using key-value format  
INSERT INTO settings (setting_key, setting_value) VALUES ('auto_logout_enabled', '1') ON DUPLICATE KEY UPDATE setting_value = '1';
INSERT INTO settings (setting_key, setting_value) VALUES ('auto_logout_minutes', '5') ON DUPLICATE KEY UPDATE setting_value = '5';
