CREATE TABLE ias_additional_system_prompts (
    id BIGSERIAL PRIMARY KEY,
    scope_key VARCHAR(768) NOT NULL UNIQUE,
    channel VARCHAR(64) NOT NULL,
    account_id VARCHAR(255) NOT NULL,
    from_user_id VARCHAR(255) NOT NULL,
    context_label TEXT,
    content TEXT NOT NULL DEFAULT '',
    last_reason TEXT,
    updated_by VARCHAR(64) NOT NULL DEFAULT 'ai',
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_ias_additional_system_prompts_scope_updated
    ON ias_additional_system_prompts(scope_key, updated_at DESC);
