Add migration to set profile modified date (#1832)

If modified field doesn't exist on older browser profiles, set it equal
to created date to match what we do for new profile creation.
This commit is contained in:
Tessa Walsh 2024-05-29 15:56:27 -04:00 committed by GitHub
parent 523ad68880
commit 18e5ed94f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -17,7 +17,7 @@ from pymongo.errors import InvalidName
from .migrations import BaseMigration
CURR_DB_VERSION = "0026"
CURR_DB_VERSION = "0027"
# ============================================================================

View File

@ -0,0 +1,34 @@
"""
Migration 0027 - Profile modified date fallback
"""
from btrixcloud.migrations import BaseMigration
MIGRATION_VERSION = "0027"
class Migration(BaseMigration):
"""Migration class."""
# pylint: disable=unused-argument
def __init__(self, mdb, **kwargs):
super().__init__(mdb, migration_version=MIGRATION_VERSION)
async def migrate_up(self):
"""Perform migration up.
If profile doesn't have modified date, set to created
"""
# pylint: disable=duplicate-code
profiles = self.mdb["profiles"]
try:
await profiles.update_many(
{"modified": None}, [{"$set": {"modified": "$created"}}]
)
# pylint: disable=broad-exception-caught
except Exception as err:
print(
f"Error adding modified date to profiles: {err}",
flush=True,
)