From 68b7b3f0f3bf6165956a7cec5983de61ed28292a Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 20 May 2026 22:03:59 -0400 Subject: [PATCH] fix: add missing approval workflow columns to ab_directive_log (migration 002) /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 --- .../versions/002_approval_columns.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 agent_service/migrations/versions/002_approval_columns.py diff --git a/agent_service/migrations/versions/002_approval_columns.py b/agent_service/migrations/versions/002_approval_columns.py new file mode 100644 index 0000000..168716d --- /dev/null +++ b/agent_service/migrations/versions/002_approval_columns.py @@ -0,0 +1,64 @@ +"""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 + """)