""" Migration script to add description field to strategic_cooperation table Run this script to update the database schema """ import pymysql import os # Get database configuration from environment or use defaults DB_USER = os.environ.get('DB_USER') or 'official_web' DB_PASSWORD = os.environ.get('DB_PASSWORD') or 'Wp75NdTYeCtbf6Hy' DB_HOST = os.environ.get('DB_HOST') or '47.109.147.74' DB_PORT = int(os.environ.get('DB_PORT') or '3306') DB_NAME = os.environ.get('DB_NAME') or 'official_web' try: # Connect to the database conn = pymysql.connect( host=DB_HOST, port=DB_PORT, user=DB_USER, password=DB_PASSWORD, database=DB_NAME ) cursor = conn.cursor() # Check if column already exists cursor.execute(""" SELECT COUNT(*) FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = %s AND TABLE_NAME = 'strategic_cooperation' AND COLUMN_NAME = 'description' """, (DB_NAME,)) exists = cursor.fetchone()[0] > 0 if exists: print("✓ Description column already exists in strategic_cooperation table") else: # Add description column cursor.execute('ALTER TABLE strategic_cooperation ADD COLUMN description TEXT') conn.commit() print("✓ Successfully added description column to strategic_cooperation table") except Exception as e: print(f"✗ Error: {e}") if 'conn' in locals(): conn.rollback() finally: if 'conn' in locals(): conn.close() print("\nMigration completed!")