Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFRS: prototype migration framework and object_size migration (GSI-1271) #85

Merged
merged 19 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions services/ifrs/src/ifrs/migration_logic/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ def __init__(
self._staged_collections: set[str] = set()

@asynccontextmanager
async def auto_finalize(self, coll_names: str | list[str], copy_indexes: bool):
"""Use within `apply()` or `unapply()` to
async def auto_finalize(
self, coll_names: str | list[str], copy_indexes: bool = False
):
"""Use within `apply()` or `unapply()` as a context manager to automatically
stage the temporary migrated collections for the specified collection names and
then drop the old collections. Set `copy_indexes` to True if the indexes are
expected to be identical between the old and new collection versions.

Should be used for most migrations, but complex migrations might need to take
a more manual approach. For that reason, this context manager is optional.
Expand All @@ -97,7 +102,7 @@ async def auto_finalize(self, coll_names: str | list[str], copy_indexes: bool):

# copy indexes if needed (not implemented yet)
if copy_indexes:
pass
raise NotImplementedError("Index copying is not yet implemented")
mephenor marked this conversation as resolved.
Show resolved Hide resolved
# Drop old collections. Don't do the index copy check unless we perform the
# index copying via this method. Otherwise we can't be sure it wasn't
# handled some other way
Expand Down Expand Up @@ -190,8 +195,8 @@ async def stage_collection(self, original_coll_name: str):

# Rename the old collection by giving it a prefix
# e.g. "users" -> "tmp_v7_old_users"
old_collection = self._db[original_coll_name]
temp_old_coll_name = self.old_temp_name(original_coll_name)
old_collection = self._db[original_coll_name]
await old_collection.rename(temp_old_coll_name)

# Rename the new, temp collection by removing its prefix
Expand Down Expand Up @@ -256,7 +261,9 @@ async def drop_old_collections(self, *, enforce_indexes: bool):
old_temp_name = self.old_temp_name(coll_to_drop)
collection = self._db[old_temp_name]
await collection.drop()
log.debug("Dropped old collection")
log.debug(
"Dropped old collection for '%s' ('%s')", coll_to_drop, old_temp_name
)
self._staged_collections.remove(coll_to_drop)

@abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions services/ifrs/src/ifrs/migration_logic/ifrs_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def remove_object_size(self, doc: Document) -> Document:

async def apply(self):
"""Populate `object_size` field on docs in the file_metadata collection"""
async with self.auto_finalize(METADATA_COLLECTION, copy_indexes=False):
async with self.auto_finalize(METADATA_COLLECTION):
await self.migrate_docs_in_collection(
coll_name=METADATA_COLLECTION,
change_function=self.add_object_size,
Expand All @@ -61,7 +61,7 @@ async def apply(self):

async def unapply(self):
"""Remove `object_size`"""
async with self.auto_finalize(METADATA_COLLECTION, copy_indexes=False):
async with self.auto_finalize(METADATA_COLLECTION):
await self.migrate_docs_in_collection(
coll_name=METADATA_COLLECTION,
change_function=self.remove_object_size,
Expand Down
Loading