cosmo/backend/scripts/recreate_resources_table.py

28 lines
809 B
Python

"""
Recreate resources table with unique constraint
"""
import asyncio
from app.database import engine
from app.models.db.resource import Resource
from sqlalchemy import text
async def recreate_resources_table():
"""Drop and recreate resources table"""
async with engine.begin() as conn:
# Drop the table
print("🗑️ Dropping resources table...")
await conn.execute(text("DROP TABLE IF EXISTS resources CASCADE"))
print("✓ Table dropped")
# Recreate the table
print("📦 Creating resources table with new schema...")
await conn.run_sync(Resource.metadata.create_all)
print("✓ Table created")
print("\n✨ Resources table recreated successfully!")
if __name__ == "__main__":
asyncio.run(recreate_resources_table())