|
| 1 | +""" |
| 2 | +Migration 0051 - Ensure failOnContentCheck is not set for workflows without profiles |
| 3 | +""" |
| 4 | + |
| 5 | +from btrixcloud.migrations import BaseMigration |
| 6 | + |
| 7 | + |
| 8 | +MIGRATION_VERSION = "0051" |
| 9 | + |
| 10 | + |
| 11 | +# pylint: disable=duplicate-code |
| 12 | +class Migration(BaseMigration): |
| 13 | + """Migration class.""" |
| 14 | + |
| 15 | + # pylint: disable=unused-argument |
| 16 | + def __init__(self, mdb, **kwargs): |
| 17 | + super().__init__(mdb, migration_version=MIGRATION_VERSION) |
| 18 | + |
| 19 | + async def migrate_up(self) -> None: |
| 20 | + """Perform migration up. |
| 21 | +
|
| 22 | + Unset failOnContentCheck for workflows that don't have a profile set |
| 23 | + """ |
| 24 | + crawl_configs_mdb = self.mdb["crawl_configs"] |
| 25 | + |
| 26 | + match_query = { |
| 27 | + "profileid": {"$exists": False}, |
| 28 | + "config.failOnContentCheck": True, |
| 29 | + } |
| 30 | + |
| 31 | + found = 0 |
| 32 | + updated = 0 |
| 33 | + |
| 34 | + # Workflows |
| 35 | + async for config_raw in crawl_configs_mdb.find(match_query): |
| 36 | + config_id = config_raw["_id"] |
| 37 | + found += 1 |
| 38 | + |
| 39 | + try: |
| 40 | + await crawl_configs_mdb.find_one_and_update( |
| 41 | + {"_id": config_id}, |
| 42 | + { |
| 43 | + "$set": { |
| 44 | + "failOnContentCheck": False, |
| 45 | + } |
| 46 | + }, |
| 47 | + ) |
| 48 | + updated += 1 |
| 49 | + # pylint: disable=broad-exception-caught |
| 50 | + except Exception as err: |
| 51 | + print( |
| 52 | + f"Unable to unset failOnContentCheck for config {config_id}: {err}", |
| 53 | + flush=True, |
| 54 | + ) |
| 55 | + |
| 56 | + if found: |
| 57 | + print( |
| 58 | + f"Unset failOnContentCheck from {updated} of {found} profile-less configs", |
| 59 | + flush=True, |
| 60 | + ) |
0 commit comments