""" Database initialization for customer authentication collections. """ from motor.motor_asyncio import AsyncIOMotorDatabase from app.nosql import get_database from app.core.logging import get_logger logger = get_logger(__name__) async def init_customer_auth_collections(): """Initialize collections and indexes for customer authentication.""" try: db: AsyncIOMotorDatabase = get_database() # Create indexes for scm_customers collection customers_collection = db.scm_customers # Index on phone for fast lookup await customers_collection.create_index("phone", unique=True, sparse=True) # Index on customer_id for fast lookup await customers_collection.create_index("customer_id", unique=True) # Index on merchant_id for merchant-specific queries await customers_collection.create_index("merchant_id", sparse=True) # Index on status for filtering await customers_collection.create_index("status") # Compound index for merchant + status queries await customers_collection.create_index([("merchant_id", 1), ("status", 1)]) logger.info("✅ scm_customers collection indexes created") except Exception as e: logger.error(f"❌ Error initializing customer auth collections: {str(e)}", exc_info=True) raise if __name__ == "__main__": import asyncio asyncio.run(init_customer_auth_collections())