-- Migration script to add is_active and is_superuser columns to users table
-- Run this SQL to update the database schema

-- Add is_active column (default 1 for active users)
ALTER TABLE users 
ADD COLUMN IF NOT EXISTS is_active INT NOT NULL DEFAULT 1;

-- Add is_superuser column (default 0 for non-superusers)
ALTER TABLE users 
ADD COLUMN IF NOT EXISTS is_superuser INT NOT NULL DEFAULT 0;

-- Update existing users to ensure they have the default values
UPDATE users 
SET is_active = 1 
WHERE is_active IS NULL OR is_active = 0;

UPDATE users 
SET is_superuser = 0 
WHERE is_superuser IS NULL;

-- Verify the changes
SELECT 
    COUNT(*) as total_users,
    SUM(CASE WHEN is_active = 1 THEN 1 ELSE 0 END) as active_users,
    SUM(CASE WHEN is_superuser = 1 THEN 1 ELSE 0 END) as superusers
FROM users;

