You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
More convenient configuration option for migration strategy #11678
As discussed in #11110 we should come up with a more convenient way for users to set the JPA migration strategy. At the moment the config looks like this:
and dependant config for manual: spi-connections-jpa-quarkus-migration-export=<path>
Suggestion draft for new config values from my side (bold ones are the default):
db-migration-strategy=manual/update/validate
db-migration-initialize-empty=true/false
db-migration-export-path=none/
Not entirely sure about the export-path one, if we should add a default path instead in data/migration for example.
Discussion
No response
Motivation
Make it convenient to use different migration strategies while migrating
Details
Would be nice to get input from new store team (cc e.g. @hmlnarik@ahus1) if it is worth the effort or if this would not fit with the new store implementation.
It would also be really nice if it were possible to generate a the SQL file in dev mode. It actually does seem like it's possible but it's related to a different, subtle bug. I'll open a separate ticket for that.
@shawkins - I agree this would be a nice option. Still I'd see this in the area of the cloud native team. Due to this I'm removing the SRE team from this item.
Please comment if you have a different view on this.
Still I'd see this in the area of the cloud native team. Due to this I'm removing the SRE team from this item.
We can certainly implement it, but the feature ownship seems more closely related to SRE concerns and #41863
So I'm looking for additional input on priorization, the option names / values, and the relationship to any other migration / upgrade concerns - such as eventually supporting database schema changes that are safe to be done in a rolling fashion for compatible versions.
For example rather than putting everything as general start / start-dev options, you could expose this functionality via update-compatibility:
Or refator the command chain (instead of update-compatibility, have update compatibility ... and update db ...).
I can also see wanting to validate that no migration is being performed by the main start command, but having export on the start command and throwing an exception to interupt normal startup doesn't seem like a good practice.
For example rather than putting everything as general start / start-dev options, you could expose this functionality via update-compatibility:
@shawkins I don't have a strong opinion here, but I'd prefer using the general start/start-dev options, as you called it. It helps to have a unified approach on how to set up stuff as it's intuitive approach for users. The migration happens during the start/start-dev anyway, so it just changes the behavior for the migration. Having update-compability xxx does not look very intuitive to me as I don't want to read a docs on how to set it up. I'd rather use the general options for the start options.
Having update db would look better, but when we don't support running only the migration itself (executing only the Liquibase process) as by using a separate Job in the k8s deployment, I don't see a big value to do this breaking change to our deployments.
Or maybe I'm missing some of your future plans about the DB migration, validation and export.
I'd rather use the general options for the start options.
The migration happens during the start/start-dev anyway, so it just changes the behavior for the migration.
start|start-dev|import|export|bootstrap-admin user/service defaults to spi-connections-jpa-quarkus-migration-strategy=update, which means yes the migration is implicitly performed. I was not aware of this behavior for non-start commands, and I would guess users would be surprised as well. I guess this is another reason why we started documenting that you have to shut the cluster down to run any of the non-start commands that access the database. Coming at this with fresh eyes it seems we should at least default the non-start commands to validate mode with initialize-empty=true.
Ideally there should also be more of a guarentee that start isn't going to implicitly do something that would invalidate the database for other cluster members, but that is in part the responsiblity of the update-compatibility logic - thus why I'm proposing looking at the functionality in conjunction with update-compatibility.
Having update db would look better, but when we don't support running only the migration itself (executing only the Liquibase process) as by using a separate Job in the k8s deployment, I don't see a big value to do this breaking change to our deployments.
What breaking change are you referrring to?
I don't see why we can't consider having separate commands for database migration, similar to what is shown in the previous comment. The only reason not to do this is if we need the database modifications to happen only while the instance is a member of the cluster.
Or maybe I'm missing some of your future plans about the DB migration, validation and export.
I don't have anything definite, I'm just trying to make sure we're exposing this functionality in the right way.
I guess this is another reason why we started documenting that you have to shut the cluster down to run any of the non-start commands that access the database. Coming at this with fresh eyes it seems we should at least default the non-start commands to validate mode with initialize-empty=true.
+1
What breaking change are you referrring to? I don't see why we can't consider having separate commands for database migration, similar to what is shown in the previous comment. The only reason not to do this is if we need the database modifications to happen only while the instance is a member of the cluster.
Change the command update-compatibility to update compatibility as some users can leverage it in their custom scripts. But if we decide to have a separate command for explicit manual DB migration, I'd consider it.
Having the ability to explicitly run the migration before starting KC itself would even solve some issues with parallel startups as people complain about pod failures when trying to execute migration simultaneously: #41801
In that case, we might potentially guide them (if they wanna achieve ability to run KCs in parallel) to run explicitly the DB migration as a prerequisite. Something that touches this: #41002
But it's out of scope of this, I'll share some details in the #41801.
At the moment the liquibase setup needs to connect to the database to figure out which changes have been applied and which haven't been applied, and also to generate the SQL script. This is one of the fundamentals of Liquibase.
At the same time the update-compatibility command with its current commands design will not connect to the database, even modify the database. So it is design to run in a pipeline without credentials.
So when it comes to naming, I would prefer update-db [validate|export|update] instead to separate those commands.
At the same time the update-compatibility command with its current commands design will not connect to the database, even modify the database. So it is design to run in a pipeline without credentials.
@ahus1@mabartos to clarify a bit - each subcommand is distinctly handled in terms of what build and/or runtime values are expected. It's more of an organizational concern for docs, help, and how may intuit where to expect things to be. Supporting "update compatiblity ..." simultaneously with backwards compatibility with "update-compatibility" and introducing "update db ..." is easily done.
How will the operator handle this? Introducing a new command will break existing deployments as the command is not available.
Maybe a silly question, but do all the schema/db updates require downtime?
How will the operator handle this? Introducing a new command will break existing deployments as the command is not available.
I'm not suggesting that we should make any breaking changes wrt to operator behavior just yet, but it would be good to understand what @mabartos is referring to with #41801
Maybe a silly question, but do all the schema/db updates require downtime?
They should not, but you'd have to be extremely careful with what changes are allowable for the version(s) currently running in the cluster. Also some of our supported databases may require table locks to modify existing tables, so there may only be marginal benefit in those circumstances.
I'm not suggesting that we should make any breaking changes wrt to operator behavior just yet, but it would be good to understand what @mabartos is referring to with #41801
Reading between the lines of the previous comments, it seems the database update would be done using a different command, and the start/start-dev would stop doing so. If we go through that path, it may be problematic for the operator.
I'm just trying to bring attention to this detail before committing to a solution - although I like the idea of a separated command too 😅
but it would be good to understand what @mabartos is referring to with #41801
Sorry for not being fully clear. I'm just trying to find out how much the update db command will be useful. Some cases:
1. Parallel startups
The first case that I thought of where it could be useful is related to the parallel startups. Having a separate command for executing the DB schema upgrade + data migration would help to prevent issues with the upgrade/migration during parallel startups of several KC instances. It means that at the begining, one instance would run the update db as a prerequisite "job", and after that, all instances would start without need to upgrade/migrate DB.
However, after solving #41801, the first instance starts the upgrade/migration, and the rest waits for the completion. And it's most likely a better approach than dealing with the update db, having some wait mechanism and then start other instances.
So, the update db is not very needed here ⛔
2. Explicit upgrade/migration
The second case is related to the ability to explicitly execute the upgrade/migration and not deal with the start command. This helps to have separate concepts focused only on the upgrade/migration and not leaving start commands to be a monolithic command that can do everything.
Strategies usefulness:
manual ✔️ - useful because we just order that we want to get the SQL script and we do the upgrade on our own
update ❓ - might be useful as we can explicitly run the upgrade/migration between the start command. If not run, the old behavior would be applied as the upgrade/migration would be executed during the start command (some kind of same principle as with reaugmentation during start execution without the build execution)
validate ✔️ - useful as we have an intuitive approach on how to easily do the DB validation
So, I can see how it could fit to have the update db 🟢
Config "burden"
However, I can see another issue/not-very-good-thing with providing more and more commands. These commands are stateless (except the start --optimized and persisted build config) and when these commands need to have an access to the DB, you always need to provide all the runtime options for the DB.
It means that you'd need to the following (verify if DB setting is required for listed commands):
update db ... --db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgres
...
I find it very annoying from the UX perspective as it needs to repeat all these props again. And in this case, we're talking about the complete shutdown of the server, if these commands can be executed. When we have the ability to not shut down the server, and we could execute these commands alongside the started server, I don't know why I should explicitly add all these options again, because I want to execute it against the running server.
What about to have some command ./kc.sh config that would allow you to set the fundamental configuration(runtime/buildtime) that will be stored, and then(if not overriden), these commands would use the settings.
@shawkins It's a little bit out of scope, but I think we should think about it when creating a new command. It's just an idea and I don't know about all problems/benefits it could bring :) WDYT?
However, I can see another issue/not-very-good-thing with providing more and more commands.
Having differentiated commands will give us the ability to make the help much more targeted.
I find it very annoying from the UX perspective as it needs to repeat all these props again.
It's probably not clear in our docs / examples, but keycloak.conf should be preferred as much as possible.
We can probably all agree that the cli is getting a bit unwieldy - and I'd argue is masking some inconsistencies such as #41886 and #42332 and even #38894
@shawkins It's a little bit out of scope, but I think we should think about it when creating a new command. It's just an idea and I don't know about all problems/benefits it could bring :) WDYT?
We already have support for "config credentials" with our client commands kcadm / kcreg. Some users already seem confused about what is server config vs client config in particular wrt augmentation behavior - so this may require being even more explicit "./kc.sh server-config ...". However I see this getting complicated quickly in terms of whether you want to somehow merge with or overwrite the keycloak.conf contents.
Also another problem users sometimes hit is trying to use the same keycloak install for doing both dev and prod (or another profile) work. We don't offer a well defined way of separating those configs.
I find it hard to see too much benefit a dedicated command for DB migration would bring. For parallel starts, it would mean we'd need to execute a dedicated migration command before starting the server. It feels more intuitive and robust to just start the instances in parallel and the first one performs the migration if needed – which is the current approach.
What would be the use case to perform the migration manually?
I don't think that's the only consideration here, and is also something that we still have more issues with as far as I know. We're still recommending statefulsets and we still have a problem with needing to adjust the db lock timeout (or you could attribute that to a problem with long running migrations).
it would mean we'd need to execute a dedicated migration command before starting the server.
Which is very similar / related to the flow users should adopt with the update-compatibility command.
What would be the use case to perform the migration manually?
Only a couple I can think of:
Organizationally they require reviews or separate processes for DDL level changes.
There's a bug (or performance issue) in schema modification logic that is otherwise blocking the migration. The user wants to manually correct this and proceed with the migration anyway. However with a quick glance I don't see any issues that confirm this.
To prevent any coordination issues - the one about multiple migrations with parallel starts has been fixed, but there still isn't a built-in safe-guard that all cluster members will be on requisite keycloak version. By using the validate setting, migrations would be done as part of planned outages never just implicitly due to version changes.
To self-support an unsupported database.
Does any of the above absolutely require separate commands - probably not, but it certainly makes the usage clearer.
Activity
fastfrwrd commentedon Jul 25, 2022
It would also be really nice if it were possible to generate a the SQL file in dev mode.It actually does seem like it's possible but it's related to a different, subtle bug. I'll open a separate ticket for that.ahus1 commentedon Sep 1, 2025
@shawkins - I agree this would be a nice option. Still I'd see this in the area of the cloud native team. Due to this I'm removing the SRE team from this item.
Please comment if you have a different view on this.
shawkins commentedon Sep 2, 2025
We can certainly implement it, but the feature ownship seems more closely related to SRE concerns and #41863
So I'm looking for additional input on priorization, the option names / values, and the relationship to any other migration / upgrade concerns - such as eventually supporting database schema changes that are safe to be done in a rolling fashion for compatible versions.
For example rather than putting everything as general start / start-dev options, you could expose this functionality via update-compatibility:
update-compatibility db-validate [--initialize-empty=true|false]update-compatibility db-export [--initialize-empty=true|false] [--file=...]update-compatibility db-updateOr refator the command chain (instead of update-compatibility, have update compatibility ... and update db ...).
I can also see wanting to validate that no migration is being performed by the main start command, but having export on the start command and throwing an exception to interupt normal startup doesn't seem like a good practice.
cc @vmuzikar @pruivo @mabartos
mabartos commentedon Sep 2, 2025
@shawkins I don't have a strong opinion here, but I'd prefer using the general start/start-dev options, as you called it. It helps to have a unified approach on how to set up stuff as it's intuitive approach for users. The migration happens during the start/start-dev anyway, so it just changes the behavior for the migration. Having
update-compability xxxdoes not look very intuitive to me as I don't want to read a docs on how to set it up. I'd rather use the general options for the start options.Having
update dbwould look better, but when we don't support running only the migration itself (executing only the Liquibase process) as by using a separate Job in the k8s deployment, I don't see a big value to do this breaking change to our deployments.Or maybe I'm missing some of your future plans about the DB migration, validation and export.
shawkins commentedon Sep 2, 2025
start|start-dev|import|export|bootstrap-admin user/service defaults to spi-connections-jpa-quarkus-migration-strategy=update, which means yes the migration is implicitly performed. I was not aware of this behavior for non-start commands, and I would guess users would be surprised as well. I guess this is another reason why we started documenting that you have to shut the cluster down to run any of the non-start commands that access the database. Coming at this with fresh eyes it seems we should at least default the non-start commands to validate mode with initialize-empty=true.
Ideally there should also be more of a guarentee that start isn't going to implicitly do something that would invalidate the database for other cluster members, but that is in part the responsiblity of the update-compatibility logic - thus why I'm proposing looking at the functionality in conjunction with update-compatibility.
What breaking change are you referrring to?
I don't see why we can't consider having separate commands for database migration, similar to what is shown in the previous comment. The only reason not to do this is if we need the database modifications to happen only while the instance is a member of the cluster.
I don't have anything definite, I'm just trying to make sure we're exposing this functionality in the right way.
mabartos commentedon Sep 3, 2025
@shawkins
+1
Change the command
update-compatibilitytoupdate compatibilityas some users can leverage it in their custom scripts. But if we decide to have a separate command for explicit manual DB migration, I'd consider it.Having the ability to explicitly run the migration before starting KC itself would even solve some issues with parallel startups as people complain about pod failures when trying to execute migration simultaneously: #41801
In that case, we might potentially guide them (if they wanna achieve ability to run KCs in parallel) to run explicitly the DB migration as a prerequisite. Something that touches this: #41002
But it's out of scope of this, I'll share some details in the #41801.
ahus1 commentedon Sep 3, 2025
At the moment the liquibase setup needs to connect to the database to figure out which changes have been applied and which haven't been applied, and also to generate the SQL script. This is one of the fundamentals of Liquibase.
At the same time the
update-compatibilitycommand with its current commands design will not connect to the database, even modify the database. So it is design to run in a pipeline without credentials.So when it comes to naming, I would prefer
update-db [validate|export|update]instead to separate those commands.shawkins commentedon Sep 3, 2025
@ahus1 @mabartos to clarify a bit - each subcommand is distinctly handled in terms of what build and/or runtime values are expected. It's more of an organizational concern for docs, help, and how may intuit where to expect things to be. Supporting "update compatiblity ..." simultaneously with backwards compatibility with "update-compatibility" and introducing "update db ..." is easily done.
pruivo commentedon Sep 3, 2025
How will the operator handle this? Introducing a new command will break existing deployments as the command is not available.
Maybe a silly question, but do all the schema/db updates require downtime?
shawkins commentedon Sep 3, 2025
I'm not suggesting that we should make any breaking changes wrt to operator behavior just yet, but it would be good to understand what @mabartos is referring to with #41801
They should not, but you'd have to be extremely careful with what changes are allowable for the version(s) currently running in the cluster. Also some of our supported databases may require table locks to modify existing tables, so there may only be marginal benefit in those circumstances.
The basic flow usually looks like https://spring.io/blog/2016/05/31/zero-downtime-deployment-with-a-database where you have to sequentially roll in compatible versions - ideally with the ability to easily rollback a single version.
pruivo commentedon Sep 3, 2025
Reading between the lines of the previous comments, it seems the database update would be done using a different command, and the start/start-dev would stop doing so. If we go through that path, it may be problematic for the operator.
I'm just trying to bring attention to this detail before committing to a solution - although I like the idea of a separated command too 😅
mabartos commentedon Sep 4, 2025
Sorry for not being fully clear. I'm just trying to find out how much the
update dbcommand will be useful. Some cases:1. Parallel startups
The first case that I thought of where it could be useful is related to the parallel startups. Having a separate command for executing the DB schema upgrade + data migration would help to prevent issues with the upgrade/migration during parallel startups of several KC instances. It means that at the begining, one instance would run the
update dbas a prerequisite "job", and after that, all instances would start without need to upgrade/migrate DB.However, after solving #41801, the first instance starts the upgrade/migration, and the rest waits for the completion. And it's most likely a better approach than dealing with the
update db, having some wait mechanism and then start other instances.So, the
update dbis not very needed here ⛔2. Explicit upgrade/migration
The second case is related to the ability to explicitly execute the upgrade/migration and not deal with the start command. This helps to have separate concepts focused only on the upgrade/migration and not leaving start commands to be a monolithic command that can do everything.
Strategies usefulness:
manual✔️ - useful because we just order that we want to get the SQL script and we do the upgrade on our ownupdate❓ - might be useful as we can explicitly run the upgrade/migration between the start command. If not run, the old behavior would be applied as the upgrade/migration would be executed during the start command (some kind of same principle as with reaugmentation duringstartexecution without thebuildexecution)validate✔️ - useful as we have an intuitive approach on how to easily do the DB validationSo, I can see how it could fit to have the
update db🟢Config "burden"
However, I can see another issue/not-very-good-thing with providing more and more commands. These commands are stateless (except the start --optimized and persisted build config) and when these commands need to have an access to the DB, you always need to provide all the runtime options for the DB.
It means that you'd need to the following (verify if DB setting is required for listed commands):
start ... --db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgresimport ... --db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgresexport ... --db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgresupdate db ... --db=postgres", "--db-url=jdbc:postgresql://localhost/keycloak", "--db-username=postgres...
I find it very annoying from the UX perspective as it needs to repeat all these props again. And in this case, we're talking about the complete shutdown of the server, if these commands can be executed. When we have the ability to not shut down the server, and we could execute these commands alongside the started server, I don't know why I should explicitly add all these options again, because I want to execute it against the running server.
What about to have some command
./kc.sh configthat would allow you to set the fundamental configuration(runtime/buildtime) that will be stored, and then(if not overriden), these commands would use the settings.Something like executing:
And then only execute commands like(no DB props):
start ...import ...export ...update db ...@shawkins It's a little bit out of scope, but I think we should think about it when creating a new command. It's just an idea and I don't know about all problems/benefits it could bring :) WDYT?
shawkins commentedon Sep 4, 2025
Having differentiated commands will give us the ability to make the help much more targeted.
It's probably not clear in our docs / examples, but keycloak.conf should be preferred as much as possible.
We can probably all agree that the cli is getting a bit unwieldy - and I'd argue is masking some inconsistencies such as #41886 and #42332 and even #38894
We already have support for "config credentials" with our client commands kcadm / kcreg. Some users already seem confused about what is server config vs client config in particular wrt augmentation behavior - so this may require being even more explicit "./kc.sh server-config ...". However I see this getting complicated quickly in terms of whether you want to somehow merge with or overwrite the keycloak.conf contents.
Also another problem users sometimes hit is trying to use the same keycloak install for doing both dev and prod (or another profile) work. We don't offer a well defined way of separating those configs.
vmuzikar commentedon Sep 9, 2025
Just wanted to chime in on this.
I find it hard to see too much benefit a dedicated command for DB migration would bring. For parallel starts, it would mean we'd need to execute a dedicated migration command before starting the server. It feels more intuitive and robust to just start the instances in parallel and the first one performs the migration if needed – which is the current approach.
What would be the use case to perform the migration manually?
shawkins commentedon Sep 11, 2025
I don't think that's the only consideration here, and is also something that we still have more issues with as far as I know. We're still recommending statefulsets and we still have a problem with needing to adjust the db lock timeout (or you could attribute that to a problem with long running migrations).
Which is very similar / related to the flow users should adopt with the update-compatibility command.
Only a couple I can think of:
Organizationally they require reviews or separate processes for DDL level changes.
There's a bug (or performance issue) in schema modification logic that is otherwise blocking the migration. The user wants to manually correct this and proceed with the migration anyway. However with a quick glance I don't see any issues that confirm this.
To prevent any coordination issues - the one about multiple migrations with parallel starts has been fixed, but there still isn't a built-in safe-guard that all cluster members will be on requisite keycloak version. By using the validate setting, migrations would be done as part of planned outages never just implicitly due to version changes.
To self-support an unsupported database.
Does any of the above absolutely require separate commands - probably not, but it certainly makes the usage clearer.