-- Remove legacy users.role_id after roles are stored in user_roles

INSERT INTO user_roles (user_id, role_id)
SELECT id, role_id
FROM users
WHERE role_id IS NOT NULL
  AND deleted_at IS NULL
ON CONFLICT (user_id, role_id) DO NOTHING;

ALTER TABLE users DROP COLUMN IF EXISTS role_id;
