generated from ghga-de/microservice-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cito
approved these changes
Jan 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work and very readable description (this can later go into the documentation).
Made some suggestions to consider in this PR or later.
mephenor
requested changes
Jan 21, 2025
mephenor
reviewed
Jan 22, 2025
mephenor
reviewed
Jan 22, 2025
mephenor
requested changes
Jan 22, 2025
mephenor
approved these changes
Jan 22, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a very rough version of the migration framework which aims to minimize the amount of related code required to be maintained across services without being too restricting/prescriptive.
Step 1: The logic for every migration should subclass
MigrationDefinition
and, usually,Reversible
as well:Step 2: Define the current database version and the migration map.
Step 3: Instantiate the
MigrationManager
viaasync with
, then call.migrate_or_wait()
:Step 4: Perform the DB migrations/version check sometime before firing up the actual service code:
Notes
The
MigrationDefinition
class defines some useful logic for common operations, such as "staging" migrated data (where we rename the collections to swap the new data with the old), dropping new collections, generating temp table prefixing, applying an update function to each doc in a collection with validation, and a context manager to automate staging/dropping/error case cleanup.The
MigrationManager
handles higher-level responsibilities and is ignorant of migration implementation details. It cares about whether or not the database is set up for migrations, determining which migrations it needs to run to get from version X to version Y, and running said migrations. It handles the database "lock" document to ensure only one service instance ever performs migrations, as well as maintaining a record past migrations.Solving the catch-22 of making sure only one instance initializes the lock & versioning collections is straightforward: the code inserts a lock document with a fixed ID. If the result is a
DuplicateKeyError
error, stop and enter the waiting cycle (another instance was faster), otherwise continue with the init & migration logic. The service instance that performs the initialization will already have the lock acquired after finishing setup and can roll right into executing any migrations.Currently one test case added that covers the following:
Outstanding items planned or in progress for official framework:
Reversible
subclass thing could probably be done differently