-- FIX PASSWORD HASH for default owner
-- Sets password to: admin123
UPDATE users
SET password_hash = '$2y$10$.HiyQoXM44F508nrAmDje.qwx1/VHT0QLCaOt/8Y05EGwJ.cUCFBW', is_active=1
WHERE tenant_id=1 AND email='owner@rajawali.local';

-- Ensure owner role exists and assigned
INSERT INTO roles (tenant_id,name,is_system) VALUES (1,'owner',1)
ON DUPLICATE KEY UPDATE name=VALUES(name);

INSERT IGNORE INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u JOIN roles r ON r.tenant_id=u.tenant_id AND r.name='owner'
WHERE u.tenant_id=1 AND u.email='owner@rajawali.local';
