Example #1
0
def provision_new_database_for_variant_warehouse(db_name):
    """Create a variant warehouse database of the specified name and shared the collections"""
    # Passing the secrets_file override the password already in the uri
    db_handle = MongoDatabase(
        uri=cfg['mongodb']['mongo_admin_uri'],
        secrets_file=cfg['mongodb']['mongo_admin_secrets_file'],
        db_name=db_name)
    if len(db_handle.get_collection_names()) > 0:
        logger.info(f'Found existing database named {db_name}.')
    else:
        db_handle.enable_sharding()
        db_handle.shard_collections(
            collections_shard_key_map,
            collections_to_shard=collections_shard_key_map.keys())
        logger.info(f'Created new database named {db_name}.')
Example #2
0
def prepare_dest_db(mongo_source_db: MongoDatabase,
                    mongo_dest_db: MongoDatabase):
    try:
        logger.info("Dropping target database if it already exists...")
        mongo_dest_db.drop()
        logger.info("Enabling sharding in the target database...")
        mongo_dest_db.enable_sharding()
        logger.info("Sharding collections in the target database...")
        mongo_dest_db.shard_collections(
            collections_shard_key_map,
            collections_to_shard=mongo_source_db.get_collection_names())
    except Exception as ex:
        logger.error(
            f"Error while preparing destination database!\n{ex.__str__()}")
        sys.exit(1)