/approval/pending was returning 500 UndefinedColumnError because the
approval router and MCP get_pending_approvals tool both query columns
(agent_name, action_type, description, context_data, approver_id,
approval_note, updated_at) that were never added in the initial schema
migration 001.
Adds migration 002 to ALTER TABLE ab_directive_log with all seven
missing columns (all nullable so existing rows are unaffected) and an
index on updated_at for efficient polling.
Deploy: after pulling on miaai, run:
cd /root/odoo/odoo-ai && docker compose exec agent-service \
alembic -c agent_service/migrations/alembic.ini upgrade head
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
65 lines
2.4 KiB
Python
65 lines
2.4 KiB
Python
"""Add approval workflow columns to ab_directive_log
|
|
|
|
The approval router (/approval/pending, /approval/respond) and the MCP
|
|
get_pending_approvals tool both reference columns that were never added
|
|
in the initial schema migration. This migration adds them so the
|
|
/approval/pending endpoint stops returning 500 UndefinedColumnError.
|
|
|
|
New columns on ab_directive_log:
|
|
agent_name — which specialist agent created the pending-approval entry
|
|
action_type — short label for the action type (e.g. 'create_expense')
|
|
description — human-readable summary shown in the approval UI
|
|
context_data — JSONB bag for any extra context the UI needs to display
|
|
approver_id — set when a human approves/rejects (VARCHAR to allow
|
|
Odoo user IDs or system strings like '__auto__')
|
|
approval_note — free-text note from the approver
|
|
updated_at — timestamp of last status change; indexed for polling
|
|
|
|
Revision ID: 002
|
|
Revises: 001
|
|
Create Date: 2026-05-21
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
revision = '002'
|
|
down_revision = '001'
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Add approval-workflow columns to ab_directive_log.
|
|
# All columns are nullable so existing rows are not affected.
|
|
op.execute("""
|
|
ALTER TABLE ab_directive_log
|
|
ADD COLUMN IF NOT EXISTS agent_name VARCHAR(64),
|
|
ADD COLUMN IF NOT EXISTS action_type VARCHAR(64),
|
|
ADD COLUMN IF NOT EXISTS description TEXT,
|
|
ADD COLUMN IF NOT EXISTS context_data JSONB,
|
|
ADD COLUMN IF NOT EXISTS approver_id VARCHAR(64),
|
|
ADD COLUMN IF NOT EXISTS approval_note TEXT,
|
|
ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP
|
|
""")
|
|
|
|
# Index for quick polling of pending-approval rows by updated_at
|
|
op.execute("""
|
|
CREATE INDEX IF NOT EXISTS idx_dir_updated
|
|
ON ab_directive_log(updated_at DESC)
|
|
WHERE updated_at IS NOT NULL
|
|
""")
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DROP INDEX IF EXISTS idx_dir_updated")
|
|
op.execute("""
|
|
ALTER TABLE ab_directive_log
|
|
DROP COLUMN IF EXISTS updated_at,
|
|
DROP COLUMN IF EXISTS approval_note,
|
|
DROP COLUMN IF EXISTS approver_id,
|
|
DROP COLUMN IF EXISTS context_data,
|
|
DROP COLUMN IF EXISTS description,
|
|
DROP COLUMN IF EXISTS action_type,
|
|
DROP COLUMN IF EXISTS agent_name
|
|
""")
|