Spaces:
Paused

miracle / scripts /setup_pg_trgm.py
dushyantsingh0
backend stabilization
428a35c
Raw History Blame Contribute Delete
934 Bytes
import asyncio
from sqlalchemy import text
from core.database import async_session_factory
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def main():
logger.info("Connecting to database to enable pg_trgm...")
async with async_session_factory() as session:
try:
# PostgreSQL extension for fuzzy string matching/similarity
await session.execute(text("CREATE EXTENSION IF NOT EXISTS pg_trgm;"))
await session.commit()
logger.info("SUCCESS: pg_trgm extension is enabled.")
except Exception as e:
await session.rollback()
logger.error(f"FAILURE: Could not enable pg_trgm: {e}")
if "permission denied" in str(e).lower():
logger.warning("Note: You may need Superuser privileges on the DB to enable extensions.")
if __name__ == "__main__":
asyncio.run(main())