-- Migration: Ensure Seeded Users Have Roles
-- Description: Fixes missing roles for seeded users (admins, recruiters, candidates) due to previous seeder/migration race conditions.

-- 1. Fix Admins
INSERT INTO user_roles (user_id, role)
SELECT id, 'admin' FROM users WHERE identifier IN ('takeshi_yamamoto', 'kenji', 'wile_e_coyote')
ON CONFLICT (user_id, role) DO NOTHING;

-- 2. Fix Recruiters
INSERT INTO user_roles (user_id, role)
SELECT id, 'recruiter' FROM users WHERE identifier = 'maria_santos'
ON CONFLICT (user_id, role) DO NOTHING;

-- 3. Fix Candidates (including legacy ones)
INSERT INTO user_roles (user_id, role)
SELECT id, 'candidate' FROM users WHERE identifier IN (
    'paulo_santos', 'maria_email',
    'ana_silva', 'carlos_santos', 'maria_oliveira', 'pedro_costa', 'juliana_ferreira'
)
ON CONFLICT (user_id, role) DO NOTHING;
