[odb-users] Data migration question

Boris Kolpackov boris at codesynthesis.com
Tue Sep 29 10:06:56 EDT 2020


Andrew Cunningham <odb at a-cunningham.com> writes:

> The documentation is not 100% clear on one point about data migration.
> 
> As per the example, this function migrates some object types in the
> database from any version in the range [MYAPP_BASE_VERSION,2] to version 3
> 
> static const odb::data_migration_entry<3, MYAPP_BASE_VERSION>
> migrate_gender_entry (&migrate_gender);

Not exactly: this function is called if and when migrating from version
2 to version 3. The second template argument is there to detect when this
entry is no longer necessary. Quoting the manual:

"The first template argument to the data_migration_entry class template is the
 version we want this data migration function to be called for. The second
 template argument is the base model version. This second argument is
 necessary to detect the situation where we no longer need this data migration
 function. Remember that when we move the base model version forward,
 migrations from any version below the new base are no longer possible. We,
 however, may still have migration functions registered for those lower
 versions. Since these functions will never be called, they are effectively
 dead code and it would be useful to identify and remove them. [...]"


> What is not 100% clear is what happens when the current database version is
> >3 ( say 4). Will this function still be called to migrate the objects or
> do I need to update it to
> 
> static const odb::data_migration_entry<4, MYAPP_BASE_VERSION>
> migrate_gender_entry (&migrate_gender);

Normally not. This entry is a migration "step" when migrating from version
2 to version 3. If the database is currently at version 2, then it will
be called for the 2->3 step (which will then be followed by 3->4). If,
however, the database is already at version 3 then presumably the data
is already in the desired state (from this step's point of view).



More information about the odb-users mailing list