Rebuilding DB liquibase change log

During development of my application I made an error with naming and it caused issues with generating database changes. To fix this I attempted to manually change the name of the indexes in the entity and delete the parts of the DB changelog that related to this error.

Subsequently I realise this was a mistake, because I now have a gap in my database change log which means when I deploy the application to another server, some of the database actions are not carried out automatically.

Is there a way I can re-create the log for my application to be representative of all the entities that currently exist, and be free to create new log entries for any new entries I have?

Many thanks!

Hi

Recreation of existing and already applied changelogs is a non-trivial task. Because Liquibase stores all executed changelogs (id, filename, checksum) in databasechangelog system table.

So if you recreate all changelogs from scratch, then you will need to add all of them to this databasechangelog table of your existing database. In other case Liquibase will try to execute them and fail with error.

There is an another way to get missing changelog.

  • Change database name in your data store settings.
  • Recreate this new database. All existing changelogs will be applied. Database schema will not match your project data model because of this changelog modification you mentioned above.
  • Run Generate Liquibase Changelog action, you will get changelogs according to the current data model state. Update database.
  • Using any DB client manually copy databasechangelog table records related to the changelogs from previous step to your existing database.

Thank you - will this handle the scenario where the changes in the missing section are necessary for subsequent parts of the schema?

If current changelogs in not consistent state, then I am afraid the above scenario is not suitable for you. Liquibasse update will fail. You can try to fix changelog manually or recreate them from scratch.
To recreate all changelogs you need:

  • Delete existing changelogs located in the .../liquibase/changelog/2023 (2022 etc) folder.
  • Setup your data store to connect some empty or non-existent DB.
  • Recreate database - changelogs from dependencies and 010-init-user.xml will be applied to your new database.
  • Run Generate Liquibase Changelog action, you will get all changelogs according to the current data model state. Updata database.
  • Copy all databasechangelog table records of the new database to your existing database.

Thank you for your help.

I have taken the following steps:

  1. Create a new, empty postgres DB
  2. Adjust my connection string to point at this new DB
  3. Remove all 2023/ changelogs (there are no others, other than the init user one)
  4. Start application.

I don’t get a prompt asking me to create new changelogs, and after a while I get an error which is being caused by an app specific instance of the jmix config interface not having a table in the database:

Internal Exception: org.postgresql.util.PSQLException: ERROR: relation “settings_signing” does not exist
Position: 120
Error Code: 0

I have checked my DB server, the new database has a number of jmix tables in it, along with a new, shorter dbchangelog table, which has rows relating to these newly created tables in it.

Can you assist further?

Many thanks!

Hi

When saying “app specific instance of the jmix config interface” do you mean Application Settings add-on and inheritor of the io.jmix.appsettings.entity.AppSettingsEntity entity definded in your project? In this case Studio should create changelog for such entity as it does for any other JPA entity. Please provide entity source if possible so we can check if there are some issues with entity definition.

If it is not the case, please provide some details about this “app specific instance of the jmix config interface”.

Hi,

Yes, you’re absolutely right! I worded my message very badly!

Here you go, I’ve removed the internal methods but can include these if needed:

@JmixEntity
@Table(name = “SETTINGS_SIGNING”)
@Entity
public class SigningSettings extends AppSettingsEntity {

… SNIP …
}

As we can see, it is an ordinary entity, so Studio should generate createTable changelog for it.
Unfortunately at this point I have no idea why the table was not created.

You can create new test entity to make sure that changelog generation works correct.
Make sure that there is no “SETTINGS_SIGNING” table in the DB, and no
<createTable tableName="SETTINGS_SIGNING">
changeset among generated changelogs.

Full stacktrace of the exception Internal Exception: org.postgresql.util.PSQLException: ERROR: relation “settings_signing” does not exist would be helpful.
Also idea.log file can contain some valuable information.

To provide an update to this: I’ve tried this again to generate an exception log for you, but the re-build seems to have worked this time without error… Which is great but i’m slightly confused as to what was going wrong before.