import mysql.connector
from db import DB_CONFIG

def alter_database():
    try:
        conn = mysql.connector.connect(**DB_CONFIG)
        cursor = conn.cursor()
        
        # Add original_params and color_name columns
        alter_queries = [
            "ALTER TABLE orders ADD COLUMN original_params JSON DEFAULT NULL AFTER updated_at",
            "ALTER TABLE orders ADD COLUMN color_name VARCHAR(100) DEFAULT NULL AFTER material_price"
        ]
        
        for query in alter_queries:
            try:
                cursor.execute(query)
                print(f"Executed: {query}")
            except mysql.connector.Error as e:
                print(f"Command error: {e}")
                
        conn.commit()
        print("Database migration completed successfully")
        
    except mysql.connector.Error as err:
        print(f"Error connecting to MySQL: {err}")
    finally:
        if 'conn' in locals() and conn.is_connected():
            cursor.close()
            conn.close()

if __name__ == "__main__":
    alter_database()
