PostMigrationEvent fires even if no migration was run


I’m building a JpaEntityProviderFactory, and I’d like some code to run once the JPA changelog (liquibase) migration has run. I set up an event listener like this:

  public void postInit(KeycloakSessionFactory factory) {
        (event) -> {
          if (event instanceof PostMigrationEvent)
            KeycloakModelUtils.runJobInTransaction(factory, this::initAttributes);

The problem is that the PostMigrationEvent event fires even if the JPA changelog migration has already run on previous startups. A few questions:

  1. Is this the expected behavior?
  2. Is there a better way to have some code run only once, after the JPA changelog migration has been run?

Thanks for the help.