-- V004: ai_agent_group_members
-- AI 에이전트 그룹 멤버 테이블 (execution_order 로 mixed 모드 지원)

CREATE TABLE ai_agent_group_members (
    id               BIGSERIAL PRIMARY KEY,
    group_id         BIGINT NOT NULL REFERENCES ai_agent_groups(id) ON DELETE CASCADE,
    agent_id         BIGINT NOT NULL REFERENCES ai_agents(id) ON DELETE RESTRICT,
    role_name        VARCHAR(100) NOT NULL,
    connectors       JSONB NOT NULL DEFAULT '[]'::jsonb,
    execution_order  INTEGER NOT NULL DEFAULT 1,
    config           JSONB NOT NULL DEFAULT '{}'::jsonb,
    created_at       TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at       TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_group_members_group ON ai_agent_group_members (group_id, execution_order);
