74 lines
2.4 KiB
Python
74 lines
2.4 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 fix_test_category_position():
|
|
engine = create_async_engine(DATABASE_URL, echo=False)
|
|
|
|
async with engine.connect() as conn:
|
|
print("=" * 80)
|
|
print("Restoring Test Category Position")
|
|
print("=" * 80)
|
|
|
|
# 1. 找到基础数据管理目录
|
|
print("\n[1] Finding Base Data Management directory...")
|
|
result = await conn.execute(text("""
|
|
SELECT menu_id, menu_name FROM sys_menu WHERE menu_id = 2036
|
|
"""))
|
|
row = result.fetchone()
|
|
if row:
|
|
base_data_id = row[0]
|
|
print(f" Found: ID:{row[0]} | {row[1]}")
|
|
else:
|
|
print(" [ERROR] Base Data Management directory not found!")
|
|
return
|
|
|
|
# 2. 将测试分类移回基础数据管理下
|
|
print("\n[2] Moving Test Category back to Base Data Management...")
|
|
await conn.execute(text(f"""
|
|
UPDATE sys_menu
|
|
SET parent_id = {base_data_id}, order_num = 1
|
|
WHERE path = 'test_category' AND menu_type = 'C'
|
|
"""))
|
|
await conn.commit()
|
|
print(" [OK] Test Category moved back to Base Data Management")
|
|
|
|
# 3. 验证
|
|
print("\n[3] Verification:")
|
|
result = await conn.execute(text(f"""
|
|
SELECT m.menu_id, m.menu_name, m.path, m.order_num, p.menu_name as parent_name
|
|
FROM sys_menu m
|
|
LEFT JOIN sys_menu p ON m.parent_id = p.menu_id
|
|
WHERE m.path = 'test_category'
|
|
"""))
|
|
row = result.fetchone()
|
|
if row:
|
|
print(f" Test Category: ID:{row[0]} | {row[1]}")
|
|
print(f" Parent: {row[4]} (ID: {row[0]})")
|
|
print(f" Order: {row[3]}")
|
|
|
|
print("\n" + "=" * 80)
|
|
print("Restore Complete")
|
|
print("=" * 80)
|
|
|
|
await engine.dispose()
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.run(fix_test_category_position())
|