57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
Add itemImage column to items table
|
|
"""
|
|
|
|
import mysql.connector
|
|
|
|
# Database configuration
|
|
DB_CONFIG = {
|
|
'host': 'localhost',
|
|
'port': 31175,
|
|
'user': 'root',
|
|
'password': 'vLuH6WhOTMm5O9CarrAX4S5F',
|
|
'database': 'aliexpress',
|
|
'charset': 'utf8mb4'
|
|
}
|
|
|
|
|
|
def add_column():
|
|
"""Add itemImage column to items table if it doesn't exist"""
|
|
try:
|
|
conn = mysql.connector.connect(**DB_CONFIG)
|
|
cursor = conn.cursor()
|
|
|
|
# Check if column already exists
|
|
cursor.execute("""
|
|
SELECT COUNT(*)
|
|
FROM information_schema.COLUMNS
|
|
WHERE TABLE_SCHEMA = 'aliexpress'
|
|
AND TABLE_NAME = 'items'
|
|
AND COLUMN_NAME = 'itemImage'
|
|
""")
|
|
|
|
exists = cursor.fetchone()[0]
|
|
|
|
if exists:
|
|
print("Column 'itemImage' already exists")
|
|
else:
|
|
# Add the column
|
|
cursor.execute("""
|
|
ALTER TABLE items
|
|
ADD COLUMN itemImage VARCHAR(255)
|
|
AFTER itemImageURL
|
|
""")
|
|
conn.commit()
|
|
print("Column 'itemImage' added successfully")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except mysql.connector.Error as err:
|
|
print(f"Database error: {err}")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
add_column()
|