-- Migration: Add hashed_password column to users table
-- Run this if you have an existing database without the password column

-- Add hashed_password column if it doesn't exist
DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM information_schema.columns
                   WHERE table_name = 'users' AND column_name = 'hashed_password') THEN
        ALTER TABLE users ADD COLUMN hashed_password VARCHAR(255);
    END IF;
END $$;

-- Update test user with password "password123" (bcrypt hash)
UPDATE users
SET hashed_password = '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/X.9QYQxQj9oQx9zWe'
WHERE email = 'test@forge.ai' AND hashed_password IS NULL;

-- If no test user exists, create one
INSERT INTO users (id, email, hashed_password, display_name, role, is_active)
SELECT 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
       'test@forge.ai',
       '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/X.9QYQxQj9oQx9zWe',
       'Test User',
       'admin',
       true
WHERE NOT EXISTS (SELECT 1 FROM users WHERE email = 'test@forge.ai');
