-- Quick Update Script - Add Missing Columns
-- This will update your existing database without losing data

USE fast_earn_2;

-- Add username column if it doesn't exist
ALTER TABLE users ADD COLUMN IF NOT EXISTS username VARCHAR(50) UNIQUE DEFAULT NULL COMMENT 'Username for admin login' AFTER id;

-- Add role column if it doesn't exist
ALTER TABLE users ADD COLUMN IF NOT EXISTS role ENUM('user', 'admin') DEFAULT 'user' COMMENT 'User role' AFTER password;

-- Update admin user (ID = 1) with username and role
UPDATE users SET username = 'admin', role = 'admin', full_name = 'Administrator' WHERE id = 1;

-- Set all other users to role 'user'
UPDATE users SET role = 'user' WHERE id != 1 AND role IS NULL;

SELECT 'Database updated successfully!' as Status;
