Skip to content

Commit

Permalink
Add migration to set profile modified date (#1832)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tw4l authored May 29, 2024
1 parent 523ad68 commit 18e5ed9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/btrixcloud/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .migrations import BaseMigration


CURR_DB_VERSION = "0026"
CURR_DB_VERSION = "0027"


# ============================================================================
Expand Down
34 changes: 34 additions & 0 deletions backend/btrixcloud/migrations/migration_0027_profile_modified.py
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 18e5ed9

Please sign in to comment.