50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Migration: Remove attacker_hp and defender_hp columns from pvp_combats table
|
|
These fields are no longer needed as we use player HP directly from players table.
|
|
"""
|
|
import asyncio
|
|
from api.database import engine
|
|
from sqlalchemy import text
|
|
|
|
async def migrate():
|
|
"""Remove HP fields from pvp_combats table"""
|
|
|
|
async with engine.begin() as conn:
|
|
print("🔧 Starting migration: Remove attacker_hp and defender_hp from pvp_combats...")
|
|
|
|
# Check if columns exist
|
|
check_query = text("""
|
|
SELECT column_name
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'pvp_combats'
|
|
AND column_name IN ('attacker_hp', 'defender_hp')
|
|
""")
|
|
result = await conn.execute(check_query)
|
|
existing_columns = result.fetchall()
|
|
|
|
if not existing_columns:
|
|
print("✅ Columns already removed. Nothing to do.")
|
|
return
|
|
|
|
column_names = [row[0] for row in existing_columns]
|
|
print(f"Found {len(existing_columns)} column(s) to remove: {column_names}")
|
|
|
|
# Drop the columns
|
|
if 'attacker_hp' in column_names:
|
|
print("Dropping attacker_hp column...")
|
|
await conn.execute(text("ALTER TABLE pvp_combats DROP COLUMN IF EXISTS attacker_hp"))
|
|
print("✅ Dropped attacker_hp")
|
|
|
|
if 'defender_hp' in column_names:
|
|
print("Dropping defender_hp column...")
|
|
await conn.execute(text("ALTER TABLE pvp_combats DROP COLUMN IF EXISTS defender_hp"))
|
|
print("✅ Dropped defender_hp")
|
|
|
|
print("✅ Migration completed successfully!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(migrate())
|
|
|
|
|