import mysql.connector
from db import DB_CONFIG

def add_chat_flag():
    try:
        conn = mysql.connector.connect(**DB_CONFIG)
        cursor = conn.cursor()
        
        query = "ALTER TABLE users ADD COLUMN can_chat BOOLEAN DEFAULT TRUE AFTER role"
        try:
            cursor.execute(query)
            print(f"Executed: {query}")
        except mysql.connector.Error as e:
            print(f"Error: {e}")
            
        conn.commit()
        print("Migration completed")
        
    except mysql.connector.Error as err:
        print(f"Connection error: {err}")
    finally:
        if 'conn' in locals() and conn.is_connected():
            cursor.close()
            conn.close()

if __name__ == "__main__":
    add_chat_flag()
