-- Migration: Update Super Admin to 'lol' and force password reset
-- Description: Updates the superadmin identifier, email, name, and sets status to enforce password change.

-- Increase status column length to support 'force_change_password' (21 chars)
ALTER TABLE users ALTER COLUMN status TYPE VARCHAR(50);
-- Safely change the superadmin identifier ONLY if 'lol' is not already taken.
DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM users WHERE identifier = 'lol') THEN
        UPDATE users
        SET identifier = 'lol',
            updated_at = CURRENT_TIMESTAMP
        WHERE identifier = 'superadmin';
    ELSE
        RAISE NOTICE 'Skipping identifier change: ''lol'' already exists';
    END IF;
END$$;

-- Update non-identifier fields for the superadmin row (if present)
UPDATE users
SET
    email = 'lol@gohorsejobs.com',
    full_name = 'Dr. Horse Expert',
    name = 'Dr. Horse Expert',
    status = 'force_change_password',
    updated_at = CURRENT_TIMESTAMP
WHERE identifier = 'superadmin' OR identifier = 'lol' OR email = 'admin@gohorsejobs.com';
