Initialisation depot
This commit is contained in:
56
AliExpress/add_column.py
Normal file
56
AliExpress/add_column.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# -*- 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()
|
||||
Reference in New Issue
Block a user