Liquibase generate changelog for Db first approach

Hi,

currently we’re working with Jmix in a DB first approach. What can we do to generate the changelog for the whole db so that we can change easily from postgresql to mssql?

Hi,
What do you mean by DB first approach?
Do you create tables in the database, and then create entities in the Jmix project by using Generate Model feature?

Yes indeed. We’re always developing DB first however i see that when running JMIX for the first time, it creates default database tables so it’s a handy thing to have for deployments.

  1. Liquibase changelog files in Jmix can support multiple database types with one set of scripts. In the Main Data Store settings dialog you should explicitly specify flag “Enable support for several DB types” and specify which DBMS types it is necessary to support.

  2. When Jmix Studio runs “Generate Model” action and creates entities based on their table definitions, it marks entities with @DdlGeneration(value = DdlGeneration.DbScriptGenerationMode.DISABLED) annotation.
    It means that Liquibase changelogs won’t be generated for such entities.
    To enable Liquibase script generation for imported entities, you can just remove this annotation (or change the corresponding setting in the entity designer).

Note that if you are using “db first” with Liquibase changelogs, you are going to have problems with running application on that particular database where you have created database tables first.
Liquibase changelog will inevitably try to be executed there, and they will fail because the tables already exist.

  1. Liquibase changelogs are always generated by comparing project’s data model with some database.
    After all entities were imported with Generate Model feature, in order to generate full changelog - you will need to change Main Data Store connection to some empty database, and then run Generate Liquibase Changelog action.
    Studio will run built-in Jmix scripts on the empty database first, then compare database with the data model, detect missing tables and will generate changelog files for all entities where DDL generation is enabled.
1 Like