[odb-users] Schema Migration not working correctly
Boris Kolpackov
boris at codesynthesis.com
Tue Jun 16 09:21:00 EDT 2020
Try the following minimal test (it's always a good idea to try to
reproduce the problem on a minimal test). It works for me and if it
works for you, try to see what's different compared to your project.
$ cd /tmp
$ cat <<EOF >test.hxx
#pragma db model version(1, 1)
#pragma db object
struct test
{
#pragma db id auto
unsigned long id_;
};
EOF
$ mkdir -p PROJDIR/cmake-build-debug/odb_gen
$ odb -d mysql --generate-query --generate-schema --schema-format separate \
--std c++17 --changelog odb-changelog.log --changelog-dir PROJDIR \
--output-dir PROJDIR/cmake-build-debug/odb_gen test.hxx
PROJDIR/odb-changelog.log: info: initializing changelog with base version 1
$ cat PROJDIR/odb-changelog.log
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="mysql" version="1">
<model version="1">
<table name="test" options="ENGINE=InnoDB" kind="object">
<column name="id" type="BIGINT UNSIGNED" null="false"/>
<primary-key auto="true">
<column name="id"/>
</primary-key>
</table>
</model>
</changelog>
$ cat <<EOF >test.hxx
#pragma db model version(1, 2)
#pragma db object
struct test
{
#pragma db id auto
unsigned long id_;
int data;
};
EOF
$ odb -d mysql --generate-query --generate-schema --schema-format separate \
--std c++17 --changelog odb-changelog.log --changelog-dir PROJDIR \
--output-dir PROJDIR/cmake-build-debug/odb_gen test.hxx
$ cat PROJDIR/odb-changelog.log
<changelog xmlns="http://www.codesynthesis.com/xmlns/odb/changelog" database="mysql" version="1">
<changeset version="2">
<alter-table name="test">
<add-column name="data" type="INT" null="false"/>
</alter-table>
</changeset>
<model version="1">
<table name="test" options="ENGINE=InnoDB" kind="object">
<column name="id" type="BIGINT UNSIGNED" null="false"/>
<primary-key auto="true">
<column name="id"/>
</primary-key>
</table>
</model>
</changelog>
More information about the odb-users
mailing list