Files
echoes-of-the-ash/migrations/migrate_add_movement_cooldown.py
2025-11-07 15:27:13 +01:00

41 lines
1.2 KiB
Python

"""
Migration: Add last_movement_time column to players table
"""
import asyncio
import sys
sys.path.insert(0, '/app')
from api import database as db
async def migrate():
await db.init_db()
try:
async with db.DatabaseSession() as session:
# Check if column exists
result = await session.execute(db.text("""
SELECT COUNT(*)
FROM information_schema.columns
WHERE table_name = 'players'
AND column_name = 'last_movement_time'
"""))
count = result.scalar()
if count == 0:
print("Adding last_movement_time column to players table...")
await session.execute(db.text("""
ALTER TABLE players
ADD COLUMN last_movement_time FLOAT DEFAULT 0
"""))
await session.commit()
print("✅ Column added successfully!")
else:
print("⚠️ Column last_movement_time already exists, skipping.")
except Exception as e:
print(f"❌ Error: {e}")
raise
if __name__ == "__main__":
asyncio.run(migrate())