From 8eadb17d2f4c523878eabba2d91eadbb640d7cc2 Mon Sep 17 00:00:00 2001 From: Josh XT Date: Mon, 23 Dec 2024 05:21:21 -0500 Subject: [PATCH] add migration --- agixt/DB.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/agixt/DB.py b/agixt/DB.py index aa914f70aa3c..e3ded6d429a1 100644 --- a/agixt/DB.py +++ b/agixt/DB.py @@ -808,6 +808,49 @@ def ensure_command_cascades(): raise +def ensure_message_notify_column(): + """Ensure the message table has the notify boolean column""" + import sqlite3 + import logging + from Globals import getenv + + db_path = getenv("DATABASE_NAME") + ".db" + logging.info(f"Checking message table schema in {db_path}") + + try: + with sqlite3.connect(db_path) as conn: + cursor = conn.cursor() + + # First check if table exists + cursor.execute( + "SELECT name FROM sqlite_master WHERE type='table' AND name='message'" + ) + if not cursor.fetchone(): + logging.info("Message table doesn't exist yet") + return + + # Check columns + cursor.execute("PRAGMA table_info(message)") + columns = [col[1] for col in cursor.fetchall()] + logging.info(f"Current message columns: {columns}") + + if "notify" not in columns: + logging.info("Adding notify column") + cursor.execute( + """ + ALTER TABLE message + ADD COLUMN notify BOOLEAN NOT NULL DEFAULT 0 + """ + ) + + conn.commit() + logging.info("Message table schema update completed") + + except Exception as e: + logging.error(f"Migration error: {e}") + raise + + if __name__ == "__main__": logging.info("Connecting to database...") if getenv("DATABASE_TYPE") != "sqlite": @@ -819,6 +862,10 @@ def ensure_command_cascades(): ensure_command_cascades() except Exception as e: logging.info("No command cascade constraints to update") + try: + ensure_message_notify_column() + except Exception as e: + logging.info("No message notify column to update") # Create any missing tables Base.metadata.create_all(engine) logging.info("Database tables verified/created.")