def up()

in jobs/mongodb_migration/src/mongodb_migration/migrations/_20240624144000_cache_add_estimated_num_rows_field_in_size.py [0:0]


    def up(self) -> None:
        # See https://docs.mongoengine.org/guide/migration.html#example-1-addition-of-a-field
        logging.info(
            "If missing, add the 'estimated_num_rows' field with the default value"
            " None to the cached results of dataset-size and config-size"
        )
        db = get_db(CACHE_MONGOENGINE_ALIAS)
        db[CACHE_COLLECTION_RESPONSES].update_many(
            {
                "kind": "config-size",
                "http_status": 200,
                "content.size.config.estimated_num_rows": {"$exists": False},
            },
            {
                "$set": {
                    "content.size.config.estimated_num_rows": None,
                    "content.size.splits.$[].estimated_num_rows": None,
                }
            },
        )
        db[CACHE_COLLECTION_RESPONSES].update_many(
            {
                "kind": "dataset-size",
                "http_status": 200,
                "content.size.dataset.estimated_num_rows": {"$exists": False},
            },
            {
                "$set": {
                    "content.size.dataset.estimated_num_rows": None,
                    "content.size.configs.$[].estimated_num_rows": None,
                    "content.size.splits.$[].estimated_num_rows": None,
                }
            },
        )