Skip to content

Commit d068d0e

Browse files
committed
Add migration
1 parent c41b519 commit d068d0e

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

backend/btrixcloud/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
) = PageOps = BackgroundJobOps = FileUploadOps = CrawlLogOps = object
3535

3636

37-
CURR_DB_VERSION = "0050"
37+
CURR_DB_VERSION = "0051"
3838

3939

4040
# ============================================================================
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)