[odb-users] Drop table in schema migration

Boris Kolpackov boris at codesynthesis.com
Tue Apr 19 10:01:32 EDT 2016


Hi Dieter,

Dieter Govaerts <dieter.govaerts at bricsys.com> writes:

> I meant to actually drop the table from the db as opposed to soft-delete as
> described in 13.4 of the manual. The new classes and the old classes will
> use the same names.
> 
> I currently have following classes in the db:
> - Building
> - Story
> These classes are unrelated (polymorphic wise). I would like to replace
> it with the following hierarchy:
>
>          SpatialStructure
>             ^     ^
>            /       \
>     Building       Story
>
> such that I can refer to either a building or a story with the ID of a
> SpatialStructure.
>
> As said, data migration is not important. What I wanted was to create a new
> version 5 which forgets the original classes as if they never existed (drop
> table). Then create a new version 6 with the new structure.

Thanks for clarifying this, now it makes sense.

ODB tracks changes (for schema migration) based on table names. So if you
replace your classes but keep the original table names, ODB will see it as
changes to the old classes (you can take a look at the changelog -- it is
all in terms of database schema changes, not C++ class changes).

So the simplest way to achieve what you want would be to remove the old
classes and assign new table names to the new one (with the db table()
pragma). ODB will then drop the old table and create the new ones
automatically.

You could probably make the same table name approach work with some
effort. For example, you could use the --omit-{drop,create} options to
generate schemas (probably with different names; see --schema-name) for
the new and old classes and then apply them at the right stage of the
migration process. But, as you can see, this can get involved.

Boris



More information about the odb-users mailing list