From c43ce3a17b243eebcef560143877ceb6070a2b73 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Mon, 1 Jun 2020 11:36:22 +0300 Subject: [PATCH] Update 0.15 mongo migration to drop indices (so new ones will be automatically created) --- server/mongo/migrations/0.15.0.py | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 server/mongo/migrations/0.15.0.py diff --git a/server/mongo/migrations/0.15.0.py b/server/mongo/migrations/0.15.0.py new file mode 100644 index 0000000..4831598 --- /dev/null +++ b/server/mongo/migrations/0.15.0.py @@ -0,0 +1,43 @@ +from collections import Collection +from typing import Sequence + +from pymongo.database import Database, Collection + + +def _drop_all_indices_from_collections(db: Database, names: Sequence[str]): + for collection_name in db.list_collection_names(): + if collection_name not in names: + continue + collection: Collection = db[collection_name] + collection.drop_indexes() + + +def migrate_auth(db: Database): + """ + Remove the old indices from the collections since + they may come out of sync with the latest changes + in the code and mongo libraries update + """ + _drop_all_indices_from_collections(db, ["user"]) + + +def migrate_backend(db: Database): + """ + Remove the old indices from the collections since + they may come out of sync with the latest changes + in the code and mongo libraries update + """ + _drop_all_indices_from_collections( + db, + [ + "company", + "model", + "project", + "queue", + "settings", + "task", + "task__trash", + "user", + "versions", + ], + )