60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""Run migration to add public/private feature"""
|
|
|
|
import pymysql
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables
|
|
load_dotenv()
|
|
|
|
def run_migration():
|
|
"""Execute the migration SQL"""
|
|
try:
|
|
# Connect to database
|
|
conn = pymysql.connect(
|
|
host=os.getenv('MYSQL_HOST', 'mysql.theaken.com'),
|
|
port=int(os.getenv('MYSQL_PORT', 33306)),
|
|
user=os.getenv('MYSQL_USER', 'A060'),
|
|
password=os.getenv('MYSQL_PASSWORD', 'WLeSCi0yhtc7'),
|
|
database=os.getenv('MYSQL_DATABASE', 'db_A060')
|
|
)
|
|
|
|
cursor = conn.cursor()
|
|
|
|
# Read migration file
|
|
with open('migrations/add_public_feature.sql', 'r', encoding='utf-8') as f:
|
|
sql_content = f.read()
|
|
|
|
# Execute each statement
|
|
statements = sql_content.split(';')
|
|
for statement in statements:
|
|
statement = statement.strip()
|
|
if statement and not statement.startswith('--'):
|
|
print(f"Executing: {statement[:50]}...")
|
|
cursor.execute(statement)
|
|
|
|
# Commit changes
|
|
conn.commit()
|
|
print("Migration completed successfully!")
|
|
|
|
# Verify the changes
|
|
cursor.execute("DESCRIBE todo_item")
|
|
columns = cursor.fetchall()
|
|
print("\nCurrent todo_item columns:")
|
|
for col in columns:
|
|
if col[0] in ['is_public', 'tags']:
|
|
print(f" ✓ {col[0]}: {col[1]}")
|
|
|
|
cursor.close()
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"Migration failed: {str(e)}")
|
|
return False
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
run_migration() |