[odb-users] Schema Migration not working correctly

Tschoche.Jonas at ddv-mediengruppe.de Tschoche.Jonas at ddv-mediengruppe.de
Tue Jun 16 08:51:02 EDT 2020


Yes it was a small exampe the baseentry has id and some other fields and are many other tables with datamembers. 
I use the 'embedded' (separate option) so I have no sql files - I tried to compile with format option sql and all sql with the right content are generated.
When I use the embedded - it creates the database - all it working fine, but not the schmema mirgrations - because of false written odb_changelog.
After compiling the code I looked in odb_changelog, it has following content:

<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="mysql" version="1">
  <model version="1"/>
   <changeset version="1"/>
</changelog>

When I change to
#pragma db model version(1, 2)
And recompile - it is the same result - only when I add a data member to object then apairs to the odb_changelog

After second compile:
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="mysql" version="1">
  <changeset version="2"/>

  <model version="1"/>
</changelog>

When adding a new data member: 

<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="mysql" version="1">
  <changeset version="3">
    <add-table name="Users" options="ENGINE=InnoDB" kind="object">
      <column name="ID" type="INT" null="false"/>
      <column name="CreateDate" type="DATETIME" null="true"/>
      <column name="ChangeDate" type="DATETIME" null="true"/>
      <column name="ChangedBy" type="TEXT" null="false"/>
      <column name="ChangeLocation" type="TEXT" null="false"/>
      <column name="Name" type="VARCHAR(255)" null="false"/>
      <column name="MYNEWDATAMEMBER" type="TEXT" null="false"/>
      <column name="EMail" type="VARCHAR(80)" null="false"/>
      <column name="Password" type="VARBINARY(128)" null="false"/>
      <primary-key auto="true">
        <column name="ID"/>
      </primary-key>
      <index name="Name_i" type="UNIQUE">
        <column name="Name"/>
      </index>
      <index name="EMail_i" type="UNIQUE">
        <column name="EMail"/>
      </index>
    </add-table>
  </changeset>

  <changeset version="2"/>

  <model version="1"/>
</changelog>

All other Members (exclude MYNEWDATAMEMBER) was available on 1. And 2. Compile.

Why it don't reconized the old members on initial generate? I cleaned for this all cache data.

Am 16.06.20, 14:29 schrieb "Boris Kolpackov" <boris at codesynthesis.com>:

    Tschoche.Jonas at ddv-mediengruppe.de <Tschoche.Jonas at ddv-mediengruppe.de> writes:
    
    > BaseClass:
    > #pragma db model version(1, 1)
    > #pragma db object abstract
    > class BaseEntity {}
    > 
    > Object:
    > 
    > #pragma db object table("TABLE")
    > class TABLE : public BaseEntity {}
    
    At version 1 does your TABLE class have any data members? Try something
    like this:
    
    #pragma db object table("TABLE")
    class TABLE : public BaseEntity
    {
    public:
      #pragma db id
      int id;
    };
    
    Also, if you look into the generated .sql file (again, corresponding
    to version 1), do you see any 'CREATE TABLE' statements?
    




More information about the odb-users mailing list