browsertrix/backend/btrixcloud/migrations/migration_0013_crawl_name.py
Tessa Walsh 7ff57ce6b5
Backend: standardize search values, filters, and sorting for archived items (#1039)
- all-crawls list endpoint filters now conform to 'Standardize list controls for archived items #1025' and URL decode values before passing them in
- Uploads list endpoint now includes all all-crawls filters relevant to uploads
- An all-crawls/search-values endpoint is added to support searching across all archived item types
- Crawl configuration names are now copied to the crawl when the crawl is created, and crawl names and descriptions are now editable via the backend API (note: this will require frontend changes as well to make them editable via the UI)
- Migration added to copy existing config names for active configs into their associated crawls. This migration has been tested in a local deployment
- New statuses generate-wacz, uploading-wacz, and pending-wait are added when relevant to tests to ensure that they pass
- Tests coverage added for all new all-crawls endpoints, filters, and sort values
2023-08-04 09:56:52 -07:00

43 lines
1.2 KiB
Python

"""
Migration 0013 - Copy config name to crawls
"""
from btrixcloud.migrations import BaseMigration
MIGRATION_VERSION = "0013"
class Migration(BaseMigration):
"""Migration class."""
def __init__(self, mdb, migration_version=MIGRATION_VERSION):
super().__init__(mdb, migration_version)
async def migrate_up(self):
"""Perform migration up.
Copy crawl config names to associated crawls.
"""
# pylint: disable=duplicate-code
crawls = self.mdb["crawls"]
crawl_configs = self.mdb["crawl_configs"]
configs = [res async for res in crawl_configs.find({"inactive": {"$ne": True}})]
if not configs:
return
for config in configs:
config_id = config["_id"]
try:
if not config.get("name"):
continue
await crawls.update_many(
{"cid": config_id}, {"$set": {"name": config.get("name")}}
)
# pylint: disable=broad-exception-caught
except Exception as err:
print(
f"Unable to set name for crawls from with config {config_id}: {err}",
flush=True,
)