ALTER TABLE tasks ADD COLUMN IF NOT EXISTS source text NOT NULL DEFAULT 'manual'; ALTER TABLE tasks DROP CONSTRAINT IF EXISTS tasks_source_check; ALTER TABLE tasks ADD CONSTRAINT tasks_source_check CHECK (source IN ('manual', 'agentbus')); CREATE INDEX IF NOT EXISTS tasks_source_idx ON tasks (organization_id, source, created_at DESC);