Upgrading 18.0.2 to 19.0.2

Summary: After upgrading Keycloak docker image version from 18.0.2 to 19.0.2 database auto migration does not take place and all the data post upgrade is still present in database but not visible in admin console.

Steps to reproduce:

  1. Start MySQL database and create user/database for Keycloak
  2. Start Keycloak version 18.0.2
  docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB_URL_HOST=mysql -e KC_DB_URL_PORT=3306 -e KC_DB_URL_DATABASE=keycloak_db -e KC_DB_USERNAME=mysql_user -e KC_DB_PASSWORD=mysql_password quay.io/keycloak/keycloak:18.0.2 start-dev

  1. Create realm ‘demo’ and add user ‘user@example.com’
  2. Stop Keycloak
  3. Start Keycloak 19.0.2
docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB_URL_HOST=mysql -e KC_DB_URL_PORT=3306 -e KC_DB_URL_DATABASE=keycloak_db -e KC_DB_USERNAME=mysql_user -e KC_DB_PASSWORD=mysql_password quay.io/keycloak/keycloak:19.0.2 start-dev --spi-connections-jpa-default-migration-strategy=update

  1. See that migration is executed in the logs
 INFO  [org.keycloak.quarkus.runtime.storage.legacy.liquibase.QuarkusJpaUpdaterProvider] (main) Initializing database schema. Using changelog META-INF/jpa-changelog-master.xml
  1. Navigate to Admin Console - only master realm is available.

Is there some step that I am missing? Why I am unable to see realm created in previous version of Keycloak?

It appears that setting KC_DB environment variable is required in start command. Once I have added -e KC_DB=mysql to my docker command when starting 19.0.2 migration succeeded. Setting –spi-connections-jpa-default-migration-strategy=update is not required, as this is default value.

Here is command that worked:

docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KC_DB=mysql -e KEYCLOAK_ADMIN_PASSWORD=admin -e KC_DB_URL_HOST=mysql -e KC_DB_URL_PORT=3306 -e KC_DB_URL_DATABASE=keycloak_db -e KC_DB_USERNAME=mysql_user -e KC_DB_PASSWORD=mysql_password quay.io/keycloak/keycloak:19.0.2 start-dev

1 Like

This is also true when migrating to later version (21 in my case). KC_DB variable is mandatory. Thank you so much for finding about it :pray: