[odb-users] Data migration in SQLite

Alexander Igorevich alejandro_pnz at icloud.com
Mon Dec 12 22:08:48 EST 2016


Hi. I've read ODB manual ch. 13 and now I try to migrate my database version. I use sample from the end of chapter 13.2:

schema_version v (db.schema_version ());
schema_version bv (schema_catalog::base_version (db));
schema_version cv (schema_catalog::current_version (db));

if (v == 0)
{
  // No schema in the database. Create the schema and
  // initialize the database.
  //
  transaction t (db.begin ());
  schema_catalog::create_schema (db);

  // Populate the database with initial data, if any.

  t.commit ();
}
else if (v < cv)
{
  // Old schema (and data) in the database, migrate them.
  //

  if (v < bv)
  {
    // Error: migration from this version is no longer supported.
  }

  for (v = schema_catalog::next_version (db, v);
       v <= cv;
       v = schema_catalog::next_version (db, v))
  {
    transaction t (db.begin ());
    schema_catalog::migrate_schema_pre (db, v);

    // Data migration goes here.

    schema_catalog::migrate_schema_post (db, v);
    t.commit ();
  }
}
else if (v > cv)
{
  // Error: old application trying to access new database.
}

But after running this code on the database (it works great and function calling right), there is no new added tables (classes) in the database. I've add version notation to new class like that:

#pragma db model version(2, 2, open)
In old (1st version scheme) classes has notation like that:

#pragma db model version(1, 1, closed)
The question why migrate_schema doesn't create table for the new class? (if I remove database, code above successfully create database from the scratch with the class)?


More information about the odb-users mailing list