Spaces:
Paused

File size: 934 Bytes
428a35c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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())