From e75b207f7e04115c7a38c241118b3cd6a560e871 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Fri, 8 Sep 2023 08:17:40 -0700 Subject: [PATCH] Fix 0015 migration (#1154) * migration: fix 0015 migration to ensure it reads the correct mongo collection, avoid variable overwrites and and uses org _id field. fixes #1153 --- .../migration_0015_org_storage_usage.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/btrixcloud/migrations/migration_0015_org_storage_usage.py b/backend/btrixcloud/migrations/migration_0015_org_storage_usage.py index e4c523de..87839a4e 100644 --- a/backend/btrixcloud/migrations/migration_0015_org_storage_usage.py +++ b/backend/btrixcloud/migrations/migration_0015_org_storage_usage.py @@ -7,6 +7,7 @@ from btrixcloud.migrations import BaseMigration MIGRATION_VERSION = "0015" +# pylint: disable=too-many-locals class Migration(BaseMigration): """Migration class.""" @@ -18,29 +19,29 @@ class Migration(BaseMigration): Calculate and store org storage usage """ - orgs = self.mdb["orgs"] - crawls = self.mdb["crawls"] - profiles = self.mdb["profiles"] + mdb_orgs = self.mdb["organizations"] + mdb_crawls = self.mdb["crawls"] + mdb_profiles = self.mdb["profiles"] - orgs = [res async for res in orgs.find({})] + orgs = [res async for res in mdb_orgs.find({})] for org in orgs: - oid = org.get("id") + oid = org.get("_id") bytes_stored = 0 - crawls = [res async for res in crawls.find({"oid": oid})] + crawls = [res async for res in mdb_crawls.find({"oid": oid})] for crawl in crawls: for crawl_file in crawl.get("files", []): bytes_stored += crawl_file.get("size", 0) - profiles = [res async for res in profiles.find({"oid": org["id"]})] + profiles = [res async for res in mdb_profiles.find({"oid": oid})] for profile in profiles: profile_file = profile.get("resource") if profile_file: bytes_stored += profile_file.get("size", 0) try: - await orgs.find_one_and_update( + res = await mdb_orgs.find_one_and_update( {"_id": oid}, {"$set": {"bytesStored": bytes_stored}} ) # pylint: disable=broad-exception-caught