-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_a2a_integration_fields.py
More file actions
78 lines (62 loc) · 2.71 KB
/
add_a2a_integration_fields.py
File metadata and controls
78 lines (62 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Migration script to add A2A protocol integration fields to AIAgent table.
"""
import os
from datetime import datetime
from sqlalchemy import create_engine, Column, Boolean, String, DateTime, Integer, Text, inspect, text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# Create a direct connection to the database
def create_db_connection():
"""Create a direct SQLAlchemy engine connection to the database"""
database_url = os.environ.get('DATABASE_URL')
engine = create_engine(database_url)
return engine, sessionmaker(bind=engine)()
def add_a2a_columns():
"""Add A2A protocol integration columns to the AIAgent table"""
engine, session = create_db_connection()
# Check if the columns already exist
inspector = inspect(engine)
columns = [column['name'] for column in inspector.get_columns('ai_agent')]
columns_to_add = []
if 'a2a_enabled' not in columns:
columns_to_add.append("a2a_enabled BOOLEAN DEFAULT FALSE")
if 'bns_identifier' not in columns:
columns_to_add.append("bns_identifier VARCHAR(256) UNIQUE")
if 'a2a_metadata' not in columns:
columns_to_add.append("a2a_metadata TEXT")
if 'a2a_last_seen' not in columns:
columns_to_add.append("a2a_last_seen TIMESTAMP")
if 'a2a_interaction_count' not in columns:
columns_to_add.append("a2a_interaction_count INTEGER DEFAULT 0")
if 'purpose_code' not in columns:
columns_to_add.append("purpose_code VARCHAR(20)")
if 'entity_code' not in columns:
columns_to_add.append("entity_code VARCHAR(50)")
# Add the new columns if they don't exist
if columns_to_add:
for column_def in columns_to_add:
try:
# Add column to the table
sql = text(f"ALTER TABLE ai_agent ADD COLUMN {column_def}")
session.execute(sql)
print(f"Added column {column_def.split()[0]} to AIAgent table")
except Exception as e:
print(f"Error adding column {column_def.split()[0]}: {e}")
session.commit()
print("A2A columns added to AIAgent table")
else:
print("All A2A columns already exist in AIAgent table")
session.close()
def run_migration():
"""Run the database migration to add A2A protocol integration fields to AIAgent"""
try:
print("Starting A2A protocol integration fields migration...")
add_a2a_columns()
print("A2A protocol integration fields migration completed successfully")
return True
except Exception as e:
print(f"Migration failed: {e}")
return False
if __name__ == "__main__":
run_migration()