import os
import motor
import motor.motor_asyncio
import pymongo


MONGO_HOST = os.getenv('MONGO_HOST', 'localhost')
MONGO_PASSWORD = os.getenv('MONGO_PASSWORD', 'password')

CONNECTION_STRING = f'mongodb://mongo:{MONGO_PASSWORD}@{MONGO_HOST}:27017/'


database: 'motor.MotorDatabase' = motor.motor_asyncio.AsyncIOMotorClient(CONNECTION_STRING).queues

def create_indexes():
    client = pymongo.MongoClient(CONNECTION_STRING)
    database = client.get_database('queues')
    database.get_collection('tasks').create_index([
        ('queue', 1), 
        ('available_from', 1),
    ])
