ETest-Vue-FastAPI/check_migration.py

91 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""验证数据库迁移结果"""
import asyncio
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy import text
DB_CONFIG = {
'host': '123.57.81.127',
'port': 3306,
'user': 'cpy_admin',
'password': 'Tgzz2025+',
'database': 'ruoyi-fastapi'
}
DATABASE_URL = (
f"mysql+asyncmy://{DB_CONFIG['user']}:{DB_CONFIG['password']}@"
f"{DB_CONFIG['host']}:{DB_CONFIG['port']}/{DB_CONFIG['database']}"
)
async def check_tables():
engine = create_async_engine(DATABASE_URL, echo=False)
async with engine.connect() as conn:
print("=" * 60)
print("Database Migration Verification")
print("=" * 60)
# 1. Check test_category columns
print("\n[1] Checking test_category table...")
result = await conn.execute(text("DESCRIBE test_category"))
columns = result.fetchall()
column_names = [col[0] for col in columns]
expected_cols = ['parent_id', 'level', 'category_code', 'sort_order', 'report_config_type']
for col in expected_cols:
status = "OK" if col in column_names else "MISSING"
print(f" - {col}: {status}")
# 2. Check test_work_order columns
print("\n[2] Checking test_work_order table...")
result = await conn.execute(text("DESCRIBE test_work_order"))
columns = result.fetchall()
column_names = [col[0] for col in columns]
expected_cols = ['priority', 'expected_finish_date', 'claimed_by', 'claimed_at',
'condition_data', 'result_data', 'retest_count']
for col in expected_cols:
status = "OK" if col in column_names else "MISSING"
print(f" - {col}: {status}")
# 3. Check new tables
print("\n[3] Checking new tables...")
new_tables = [
'test_category_detail',
'test_permission',
'work_order_retest_record',
'work_order_status_history',
'report_permission',
'test_report',
'report_work_order_relation',
'test_report_version',
'report_review_record'
]
for table in new_tables:
result = await conn.execute(text(f"SHOW TABLES LIKE '{table}'"))
exists = result.fetchone() is not None
status = "OK" if exists else "MISSING"
print(f" - {table}: {status}")
# 4. Check indexes
print("\n[4] Checking indexes on test_work_order...")
result = await conn.execute(text("SHOW INDEX FROM test_work_order"))
indexes = result.fetchall()
index_names = [idx[2] for idx in indexes]
expected_indexes = ['idx_priority', 'idx_expected_finish_date', 'idx_claimed_by']
for idx in expected_indexes:
status = "OK" if idx in index_names else "MISSING"
print(f" - {idx}: {status}")
print("\n" + "=" * 60)
print("Verification Complete")
print("=" * 60)
await engine.dispose()
if __name__ == '__main__':
asyncio.run(check_tables())