[odb-users] Schema Migration not working correctly

Paul Stath PStath at jmawireless.com
Thu Apr 30 12:40:45 EDT 2020


As Boris responded, a small example will go a long way towards allowing others to help.

I had a similar experience when I first started using schema migration in my project, maybe you are having the same issue?

In the "C++ Object Persistence with ODB" manual in the "Object Model Version and Changelog" section (https://www.codesynthesis.com/products/odb/doc/manual.xhtml#13.1) is a very important paragraph.  (capitalization added for emphasis)

       "The changelog is maintained by the ODB compiler. Specifically, you do not need to make any manual changes to this file.
        You will, however, need to KEEP IT AROUND from one invocation of the ODB compiler to the next. In other words, the changelog
        file is BOTH the INPUT and the OUTPUT of the ODB compiler. This, for example, means that if your project's source code is stored
        in a version control repository, then you will most likely want to store the changelog there as well. If you delete the changelog,
        then any ability to do schema migration will be lost."

If the changelog file is not being version controlled along with your ODB persisted object headers, then the ODB compiler has no idea what the schema looked like in a previous version and will pull all tables/columns in the current version.
To get a valid changelog for your previous version (version 1), you will need to check out the sources at that version, run the ODB compiler and SAVE the changelog.
Note that this changelog should have:
    <changeset version="1">
       Content to build the schema 1 database
    </changeset>

Put this saved changelog in the working directory you are using for the development of your next version and run the ODB compiler.
Review the updated changelog file and you should see any schema changes for version 2 in:
    <changeset version="2">
       Content to modify schema version 1 to schema version 2
    </changeset>

I can tell you that when the tools are used properly, schema migration works very well.

---
Paul Stath
JMA Wireless
pstath at jmawireless.com

-----Original Message-----
From: Boris Kolpackov <boris at codesynthesis.com> 
Sent: Thursday, April 30, 2020 9:33 AM
To: Tschoche.Jonas at ddv-mediengruppe.de
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Schema Migration not working correctly

Tschoche.Jonas at ddv-mediengruppe.de <Tschoche.Jonas at ddv-mediengruppe.de> writes:

> Tody i rename a field on database. I increase the version and compiled 
> and run it. But it throw a error that the table alredy exist.

You will need to be more specific and precise about what exactly you've done. In fact, if you really did "rename a field on database" as you say, then it would have had no effect on anything ODB-related (ODB sees changes in C++ object model, not in databases).

So what you probably mean is that you have renamed a data member in a class. Or maybe you have renamed the class itself. Without knowing exactly what you've done it's hard to say what went wrong.

I suggest that you provide a small step-by-step test that reproduces the problem. For each step provide the header file to compile and the ODB command line to compile it.





More information about the odb-users mailing list