PostMigrationEvent fires even if no migration was run

Hi,

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:

  @Override
  public void postInit(KeycloakSessionFactory factory) {
    factory.register(
        (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.