"""Add transaction signing fields to agent_approvals

Revision ID: 000000000009
Revises: 000000000008
Create Date: 2026-02-13

Add 4 nullable columns to agent_approvals to support transaction intent
and wallet signing (tx_signing):
- transaction_intent: JSONB storing EVM/Solana transaction intent
- signed_transaction: TEXT storing hex/base64 signed transaction bytes
- signer_address: TEXT storing wallet address that signed
- edited_intent: JSONB storing modified intent if approver edited

All columns are nullable for backward compatibility.
"""

from alembic import op

revision = "000000000009"
down_revision = "000000000008"
branch_labels = None
depends_on = None


def upgrade() -> None:
    """Add transaction signing fields to agent_approvals."""
    op.execute("""
        ALTER TABLE agent_approvals
        ADD COLUMN transaction_intent JSONB;
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        ADD COLUMN signed_transaction TEXT;
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        ADD COLUMN signer_address VARCHAR(500);
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        ADD COLUMN edited_intent JSONB;
    """)


def downgrade() -> None:
    """Remove transaction signing fields from agent_approvals."""
    op.execute("""
        ALTER TABLE agent_approvals
        DROP COLUMN IF EXISTS transaction_intent;
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        DROP COLUMN IF EXISTS signed_transaction;
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        DROP COLUMN IF EXISTS signer_address;
    """)
    op.execute("""
        ALTER TABLE agent_approvals
        DROP COLUMN IF EXISTS edited_intent;
    """)
