What a mess
This commit is contained in:
40
migrations/migrate_add_movement_cooldown.py
Normal file
40
migrations/migrate_add_movement_cooldown.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""
|
||||
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())
|
||||
Reference in New Issue
Block a user