question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database schema migration configuration parameters not working as expected

See original GitHub issue

Describe the bug

Following https://www.keycloak.org/docs/latest/upgrading/index.html it states that you can enable manual schema migration by adding the --spi-connections-jpa-default-migration-strategy=manual parameter to the startup command.

However when doing so the expected sql file is not generated and database is migrated automatically.

Steps to reproduce the issue

services:
  keycloak:
    container_name: keycloak
    image: quay.io/keycloak/keycloak:15.0.0
    environment:
      - DB_ADDR=postgres
      - DB_USER=keycloak
      - DB_PASSWORD=keycloak-secret
    ports:
      - 8080:8080
      - 8443:8443
      - 9990:9990
    depends_on:
      - postgres
  postgres:
    image: postgres:13-alpine
    environment:
      - POSTGRES_DB=keycloak
      - POSTGRES_USER=keycloak
      - POSTGRES_PASSWORD=keycloak-secret
    ports:
      - 5432:5432
    volumes:
      - pg-volume:/var/lib/postgresql/data
volumes:
  pg-volume:
    driver: local

Run docker-compose up and wait for the database to have been setup. Close the instance and create a new docker-compose file with

services:
  keycloak:
    container_name: keycloak
    image: quay.io/keycloak/keycloak:17.0.0
    command: ["start", "--auto-build", "--spi-connections-jpa-default-migration-strategy=manual"]
    environment:
      - KC_DB=postgres
      - KC_DB_URL_HOST=postgres
      - KC_DB_URL_DATABASE=keycloak
      - KC_DB_USERNAME=keycloak
      - KC_DB_SCHEMA=public
      - KC_DB_PASSWORD=keycloak-secret
    ports:
      - 8080:8080
      - 8443:8443
      - 9990:9990
    depends_on:
      - postgres
  postgres:
    image: postgres:13-alpine
    environment:
      - POSTGRES_DB=keycloak
      - POSTGRES_USER=keycloak
      - POSTGRES_PASSWORD=keycloak-secret
    ports:
      - 5432:5432
    volumes:
      - pg-volume:/var/lib/postgresql/data
volumes:
  pg-volume:
    driver: local

Run docker-compose up again.

Version

17.0.0 Quarkus

Expected behavior

A sql file is generated instead of migrating the database automatically

Actual behavior

The database is migrated automatically

How to Reproduce?

No response

Anything else?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pedroigorcommented, Aug 4, 2022
0reactions
lmoroczcommented, Aug 4, 2022

Hi! According to PR#11110 I tried to start v19.0.1 with the manual strategy using parameters:

--spi-connections-jpa-quarkus-migration-strategy=manual --spi-connections-jpa-quarkus-initialize-empty=false --spi-connections-jpa-quarkus-migration-export="/tmp/keycloak_migr.sql"

but unfortunately it didn’t work. The database is migrated automatically and there is no export file in /tmp.

What is missing here?

In 19.0.0 there was a change in the provider id/name from quarkus to legacy (as well as QuarkusJpaConnectionProviderFactory -> LegacyJpaConnectionProviderFactory). What is the new provider id/name if I’m using db=postgres?

Update

Ok, I checked the “Provider info” page of the master realm and in v19.0.1 with db=postgres the SPI is ‘connectionsJpa’ and the provider id is legacy, so with this setup one should start with

--spi-connections-jpa-legacy-migration-strategy=manual --spi-connections-jpa-legacy-initialize-empty=false --spi-connections-jpa-legacy-migration-export="/tmp/keycloak_migr.sql"

but it depends on the <provider-id>. We should update the upgrading documentation and PR#11110 too.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting the Database Migration - Oracle Help Center
This chapter provides troubleshooting information for the migration of the database from the Sun Java System Content Delivery Server, version 2005Q4 to the ......
Read more >
Spring Boot + Hibernate + Flyway: don't run migrations on new ...
I'm using Flyway to update the DB schema. Currently, the latest version of the schema is 3 (the latest migration file is named...
Read more >
Troubleshooting migration tasks in AWS Database Migration ...
Check if the object you want to migrate is a table. If it is a view, update table mappings and specify the object-locator...
Read more >
Migration failed for TN data (upgrade from 9.10 to 10.5)
Failed migrations Trading Networks data and configuration file ... We do not have any issues while running DCC for TN and TNA database....
Read more >
Migrating Room databases | Android Developers
Learn to migrate databases safely using the Room Library. ... Automatic migrations work for most basic schema changes, but you might need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found