037_add_output_status_image_attachments.py
1 """Add status / error / image / attachments columns to the inference log. 2 3 Lets the log viewer record failures (budget / rate limit / LLM error / tool 4 crash / guard block) and user-supplied images + file attachments. Previously 5 these paths either silently dropped the row or kept only the happy-path 6 question/answer pair. 7 """ 8 import sqlalchemy as sa 9 from alembic import op 10 11 12 revision = '037' 13 down_revision = '036' 14 branch_labels = None 15 depends_on = None 16 17 18 def upgrade(): 19 try: 20 op.add_column( 21 'output', 22 sa.Column('status', sa.String(32), nullable=False, server_default='success'), 23 ) 24 except Exception as e: 25 print(f"Error adding output.status: {e}") 26 27 try: 28 op.create_index('ix_output_status', 'output', ['status']) 29 except Exception as e: 30 print(f"Error indexing output.status: {e}") 31 32 for col_name, col_type in ( 33 ('error', sa.Text()), 34 ('image', sa.Text()), 35 ('attachments', sa.Text()), 36 ): 37 try: 38 op.add_column('output', sa.Column(col_name, col_type, nullable=True)) 39 except Exception as e: 40 print(f"Error adding output.{col_name}: {e}") 41 42 43 def downgrade(): 44 for col_name in ('attachments', 'image', 'error'): 45 try: 46 op.drop_column('output', col_name) 47 except Exception as e: 48 print(f"Error dropping output.{col_name}: {e}") 49 try: 50 op.drop_index('ix_output_status', table_name='output') 51 except Exception as e: 52 print(f"Error dropping ix_output_status: {e}") 53 try: 54 op.drop_column('output', 'status') 55 except Exception as e: 56 print(f"Error dropping output.status: {e}")