From c5772c7b4bcb74d3c8292026cc0326ee26ced2ec Mon Sep 17 00:00:00 2001 From: Slipstream Date: Sun, 4 May 2025 13:56:19 -0600 Subject: [PATCH] aa --- settings_manager.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/settings_manager.py b/settings_manager.py index 0507df8..e61005e 100644 --- a/settings_manager.py +++ b/settings_manager.py @@ -65,6 +65,9 @@ async def initialize_pools(): # Initialize database schema await initialize_database() # Ensure tables exist + # Run database migrations + await run_migrations() # Apply any necessary migrations + return True # Indicate successful initialization except Exception as e: log.exception(f"Failed to initialize connection pools: {e}") @@ -100,6 +103,39 @@ async def close_pools(): # --- Database Schema Initialization --- +async def run_migrations(): + """Run database migrations to update schema.""" + if not pg_pool: + log.error("PostgreSQL pool not initialized. Cannot run migrations.") + return + + log.info("Running database migrations...") + try: + async with pg_pool.acquire() as conn: + # Check if custom_command_description column exists in command_customization table + column_exists = await conn.fetchval(""" + SELECT EXISTS ( + SELECT 1 + FROM information_schema.columns + WHERE table_name = 'command_customization' + AND column_name = 'custom_command_description' + ); + """) + + if not column_exists: + log.info("Adding custom_command_description column to command_customization table...") + await conn.execute(""" + ALTER TABLE command_customization + ADD COLUMN custom_command_description TEXT; + """) + log.info("Added custom_command_description column successfully.") + else: + log.debug("custom_command_description column already exists in command_customization table.") + + except Exception as e: + log.exception(f"Error running database migrations: {e}") + + async def initialize_database(): """Creates necessary tables in the PostgreSQL database if they don't exist.""" if not pg_pool: