42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Migration script to add player_status_effects table.
|
|
This table stores persistent status effects that can exist both during and outside of combat.
|
|
"""
|
|
import asyncio
|
|
import os
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from sqlalchemy import text
|
|
|
|
# Database connection
|
|
DB_USER = os.getenv("POSTGRES_USER")
|
|
DB_PASS = os.getenv("POSTGRES_PASSWORD")
|
|
DB_NAME = os.getenv("POSTGRES_DB")
|
|
DB_HOST = os.getenv("POSTGRES_HOST")
|
|
DB_PORT = os.getenv("POSTGRES_PORT")
|
|
DATABASE_URL = f"postgresql+psycopg://{DB_USER}:{DB_PASS}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
|
|
|
async def apply_migration():
|
|
"""Apply the status effects table migration."""
|
|
engine = create_async_engine(DATABASE_URL)
|
|
|
|
print("Applying status effects table migration...")
|
|
|
|
try:
|
|
async with engine.begin() as conn:
|
|
# Read and execute the SQL file
|
|
with open('migrations/add_status_effects_table.sql', 'r') as f:
|
|
sql = f.read()
|
|
|
|
await conn.execute(text(sql))
|
|
print("✅ Successfully created player_status_effects table")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Migration failed: {e}")
|
|
raise
|
|
finally:
|
|
await engine.dispose()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(apply_migration())
|