[odb-users] Database upgrade issue

Lonnie French lfrench at globalscape.com
Mon Jun 12 09:28:01 EDT 2017


Hello,
      I'm running into a database upgrade issue. It's not related to a schema change per se, but some value defaulting that must happen during the upgrade that is giving me problems.

My setup:
I have a multi-table database currently on schema version 5. The database is called Workspaces and the two tables I'm trying to upgrade are Workspace and Participant. Both of these tables have a column Period that was added in version 3. These are the values I'm trying to set.

My Goal:
My intent is during an upgrade of an existing database to set the value of Period for both tables but only after this column has just been added to an existing database row. So, when upgrading from a v1 or v2 database to v5, I want the value of Period for existing Workspace and Participant table entries to be a certain value. If upgrading from a database already on v3 or later I do not want to touch the value of Period.

What I've done so far:
I've added a migration method (1st snippet below) to accomplish this.

The problem I'm having:
When I upgrade only the Workspace table everything works great, but when I add the Participation table change to the upgrade an exception (1: no such column: Participation.type) gets thrown and both tables are empty after the upgrade. The "type" column was added to the Participation table in v4. The definition of the accompanying class is given by the 2nd code snippet below.


>From WorkspacesUpgrade.cpp:

static void migrate_notification_period(odb::database& db)
{
       // Default notification setting for all pre-existing workspaces
       for (Workspace& ws : db.query<Workspace>())
       {
             ws.wi.defaultNotifs.period = static_cast<uint32_t>(Shared::Period::Never);
             db.update(ws);
       }

       // Default notification setting for all pre-existing participants
       for (Participation& part : db.query<Participation>())
       {
             part.notifs.period = static_cast<uint32_t>(Shared::Period::Never);
             db.update(part);
       }
}

static const odb::data_migration_entry<3, 2> migrate_notification_period_entry(&migrate_notification_period);



>From Workspaces.h:

#pragma db object
class Participation
{
public:
       #pragma db id type("BLOB")
       Shared::ParticipationID id;

       std::wstring name;
       std::wstring email;
       #pragma db default(RecipientType::None)
       Shared::RecipientType type = Shared::RecipientType::None;
       Permissions perm;
       Notifications notifs;

       lazy_shared_ptr<Workspace> workspace;
};


I've attached the changelog (Workspaces.xml) for the Workspaces database. If I can provide any further clarification please let me know. Thank you in advance for your help

Regards,
Lonnie French | Software Engineer Manager-EFT
global<http://www.globalscape.com/>scape<http://www.globalscape.com/> | +1 (210) 308-8267 ext 5188 | NYSE MKT:GSB<http://www.globalscape.com/cgi-bin/links.cgi?page=gsb>
*This communication, including attachments, is for the exclusive use of the addressee and may contain proprietary, confidential or privileged information. If you are not the intended recipient, any use, copying, disclosure, dissemination or distribution is strictly prohibited. If you are not the intended recipient, please notify the sender immediately by return email and delete this communication and destroy all copies.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Workspaces.xml
Type: text/xml
Size: 8195 bytes
Desc: Workspaces.xml
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20170612/a31d1dee/Workspaces.bin


More information about the odb-users mailing list