configurator/app/storage/mongo/__init__.py
emmatveev 728fe12a1a
All checks were successful
Deploy Prod / Build (pull_request) Successful in 6s
Deploy Prod / Push (pull_request) Successful in 7s
Deploy Prod / Deploy prod (pull_request) Successful in 7s
fix
2024-11-24 11:31:32 +03:00

29 lines
791 B
Python

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).configurator
def create_indexes():
client = pymongo.MongoClient(CONNECTION_STRING)
database = client.get_database('configurator')
database.get_collection('configs').create_index([
('stage', 1),
('project', 1),
])
database.get_collection('experiments').create_index([
('stage', 1),
('project', 1),
])
database.get_collection('staff').create_index([
('platform_id', 1),
])