Files
itdontfitgsapi/recreate_tables.py
2025-09-23 22:58:29 -04:00

41 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Script to recreate database tables with updated schema
"""
from database import engine, Base
from sqlalchemy import text
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def recreate_tables():
"""Drop and recreate all tables"""
try:
with engine.connect() as connection:
# Drop existing tables
logger.info("Dropping existing tables...")
connection.execute(text("DROP TABLE IF EXISTS messages CASCADE"))
connection.execute(text("DROP TABLE IF EXISTS transactions CASCADE"))
connection.commit()
logger.info("✓ Tables dropped")
# Create new tables with updated schema
logger.info("Creating new tables...")
Base.metadata.create_all(bind=engine)
logger.info("✓ Tables created with updated schema")
print("\n🎉 Database tables recreated successfully!")
print("The plugin should now work with optional item_id and amount fields.")
except Exception as e:
logger.error(f"Error recreating tables: {e}")
return False
return True
if __name__ == "__main__":
print("Recreating database tables with updated schema...")
recreate_tables()