[odb-users] Use of data_migration_entry

Andrew Cunningham odb at a-cunningham.com
Wed May 15 14:51:57 EDT 2019


I must be misunderstanding something about how this is supposed to work.

Assume I have three versions of my database 1,2,3
In version 2, I introduce a new class of object "class C"
In version 3, I need to migrate some data of class C
The base version of the database is 1, and I should be able to upgrade from
1->2 or from 1->3

To handle the migration of the "class C" object from versions 2->3 , I add
a data migration entry
static void
migrate_c(odb::database& db)
{
    for (C& c: db.query<C>())
    {
       // migrate data here
        db.update(c);
    }


}

static const odb::data_migration_entry<3, 2> migrate_c_entry(&migrate_c);

This works as expected when I open a version "2" database in version "3".

However  , when I open a version "1" database, I get an exception as
migrate_c () is called.
The exception occurs, presumably, the version "1" db schema knows nothing
about objects of class "C".

I would have expected this function would NOT be called when migrating from
1->3, or at least db.query<C> would return nothing.


More information about the odb-users mailing list