-
Notifications
You must be signed in to change notification settings - Fork 210
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
chore: Migrate DatabaseVersion
to global namespace
#4192
chore: Migrate DatabaseVersion
to global namespace
#4192
Conversation
238a503
to
c7de29a
Compare
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.
🚀
c5c19dc
to
2d87eeb
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #4192 +/- ##
==========================================
+ Coverage 57.93% 58.04% +0.10%
==========================================
Files 197 197
Lines 43425 43546 +121
==========================================
+ Hits 25160 25276 +116
- Misses 18265 18270 +5 ☔ View full report in Codecov by Sentry. |
204680f
to
a760e17
Compare
a760e17
to
95474db
Compare
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.
Looks good, just some nits
// First check if the module has a `DatabaseVersion` written to | ||
// `DatabaseVersionKey` If `DatabaseVersion` already exists, there is | ||
// nothing to do. | ||
if global_dbtx | ||
.get_value(&DatabaseVersionKey(key_module_instance_id)) | ||
.await | ||
.is_none() | ||
{ |
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.
nit: early return might be slightly more readable
let current_version_in_module = if let Some(module_instance_id) = module_instance_id { | ||
remove_current_db_version_if_exists( | ||
&mut global_dbtx | ||
.to_ref_with_prefix_module_id(module_instance_id) | ||
.into_nc(), | ||
target_db_version, | ||
) | ||
.await | ||
} else { | ||
remove_current_db_version_if_exists( | ||
&mut global_dbtx.to_ref().into_nc(), | ||
target_db_version, | ||
) | ||
.await | ||
}; |
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.
nit: The actual fn call could be factored out, only the DB argument needs to change depending on the instance id being set or not.
Fixes: #3481
In developing the state machine migrations, I have found it annoying to work with
DatabaseVersion
that is within the module's namespace (since states for state machines are not kept in the module's namespace). Given that this is an existing issue, I decided to fix this first.DatabaseVersion
. Since this is a migration that needs to be applied to clients and server, and is migrating keys from modules to the global namespace, I wrote some custom migration code for this. IMO this should be the only time this is necessary, since it should not be common to move keys from modules to the global namespace.