ALTER TABLE agents ADD COLUMN is_default INTEGER NOT NULL DEFAULT 0;

CREATE UNIQUE INDEX IF NOT EXISTS idx_agents_default_per_role
ON agents(role)
WHERE is_default = 1;

INSERT INTO agents (id, name, role, tool, custom_prompt, is_default, created_at, updated_at)
SELECT
    'default-analyst-agent',
    'Default Analyst',
    'analyst',
    'codex',
    '',
    1,
    strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
    strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
WHERE NOT EXISTS (
    SELECT 1 FROM agents WHERE role = 'analyst' AND is_default = 1
);

INSERT INTO agents (id, name, role, tool, custom_prompt, is_default, created_at, updated_at)
SELECT
    'default-developer-agent',
    'Default Developer',
    'developer',
    'claude_code',
    '',
    1,
    strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
    strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
WHERE NOT EXISTS (
    SELECT 1 FROM agents WHERE role = 'developer' AND is_default = 1
);
