[odb-users] Schema evolution on existing database
boris at codesynthesis.com
Mon Oct 28 10:40:18 EDT 2019
Monika Idzik <moni.idzik at gmail.com> writes:
> However, I already have data in my current database that was created
> without model versions and schema evolution code: this means that when I'm
> adding the above code, the existing data is being removed (I assume while
> doing odb::core::schema_catalog::create_schema(*m_db);)
Probably what happens is the ODB schema evolution machinery thinks the
schema does not exist since there is no schema_version table in it. There
is actually a discussion of this situation in Section 13.2, "Schema
"Note also that above we mentioned that the schema creation statements
(person.sql) create the schema_version table. This means that if we enable
schema evolution support in the middle of a project, then we could already
have existing databases that don't include this table. As a result, ODB will
not be able to handle migrations for such databases unless we manually add the
schema_version table and populate it with the correct version information. For
this reason, it is highly recommended that you consider whether to use schema
evolution and, if so, enable it from the beginning of your project."
> Is there a way to add new columns to the existing database (so changing
> database schema) without losing existing data in the database?
The above paragraph suggests a solution: create and populate the
schema_version table manually.
More information about the odb-users