<div dir="ltr">Funny coincidence I'm actually working on making it easier to allow manual update of the database. My current approach is that databaseSchema will be deprecated in favor of two new options:<div><br></div><div>* migrationStrategy - valid values are vaildate, update and manual. Validate will just check it's up-to-date and stop the server if not. Update will automatically update. Manual will create an SQL file that can be used to manually initilze/migrate the db, then stop the server.</div><div>* initializeEmpty - if true and the db is empty it will initialize the db no matter what the migration strategy is</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 August 2016 at 22:48, Nalyvayko, Peter <span dir="ltr"><<a href="mailto:pnalyvayko@agi.com" target="_blank">pnalyvayko@agi.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nice, thanks Tom, appreciate it, I'll give it a try.<br>
Sincerely,<br>
Peter<br>
<span class="">______________________________<wbr>__________<br>
From: Thomas Darimont [<a href="mailto:thomas.darimont@googlemail.com">thomas.darimont@googlemail.<wbr>com</a>]<br>
</span>Sent: Thursday, August 18, 2016 4:30 PM<br>
<span class="">To: Nalyvayko, Peter<br>
Cc: keycloak-user<br>
Subject: Re: [keycloak-user] Database upgrade<br>
<br>
Hello Peter,<br>
<br>
</span><div><div class="h5">if you're already on 2.0.0 then you could do the following. ..<br>
Download the latest keycloak-2.1.0.Final relase and extract it.<br>
<br>
Then just run the liquibase scripts within the keycloak-model-jpa-2.1.0.<wbr>Final.jar from the classpath as shown below.<br>
This works because since version 1.9.1.Final until now (2.2.0..) the liquibase scripts<br>
only contain declarative changes (that have no deps on Keycloak classes), however<br>
earlier versions run custom migration code that requires a bunch of Keycloak application classes on the classpath.<br>
<br>
So this approach (currently) works but will require additional classpath / infrastructure changes<br>
once keycloak needs to perform some programmatic migration operations in future releases.<br>
<br>
In my test I used a database with very little data so I'd recommend that you try this<br>
on a database backup first :-)<br>
<br>
The following example is based on a database created by Keycloak version 1.9.1.Final that<br>
I want to upgrade to 2.1.0.Final.<br>
<br>
My current directory:<br>
tom@euler ~/dev/playgroud/keycloak/<wbr>keycloak-2.1.0.Final<br>
<br>
# Configure PG JDBC Driver jar<br>
POSTGRES_JDBC_LIB=~/.m2/<wbr>repository/org/postgresql/<wbr>postgresql/9.4.1209.jre7/<wbr>postgresql-9.4.1209.jre7.jar<br>
# Keycloak Deps<br>
KEYCLOAK_DEPS_LIB=modules/<wbr>system/layers/base/org/jboss/<wbr>logging/main/jboss-logging-3.<wbr>3.0.Final.jar<br>
# Keycloak JPA Model jar contains the liquibase migration scripts<br>
KEYCLOAK_JPA_MODEL_LIB=<wbr>modules/system/layers/<wbr>keycloak/org/keycloak/<wbr>keycloak-model-jpa/main/<wbr>keycloak-model-jpa-2.1.0.<wbr>Final.jar<br>
<br>
# Manually execute the database update<br>
java -jar modules/system/layers/<wbr>keycloak/org/liquibase/main/<wbr>liquibase-core-3.4.1.jar \<br>
--driver=org.postgresql.Driver \<br>
--classpath="$POSTGRES_JDBC_<wbr>LIB:$KEYCLOAK_DEPS_LIB:$<wbr>KEYCLOAK_JPA_MODEL_LIB" \<br>
--changeLogFile=META-INF/jpa-<wbr>changelog-master.xml \<br>
--url="jdbc:postgresql://<wbr>localhost:5432/keycloak_<wbr>migration_test" \<br>
--username=keycloak \<br>
--password=keycloak \<br>
--logLevel=debug \<br>
update<br>
<br>
The migration logs were actually quite big so I pasted them here for reference:<br>
<a href="https://gist.github.com/thomasdarimont/4d24215681b395361abd6736fa8ce36c" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>thomasdarimont/<wbr>4d24215681b395361abd6736fa8ce3<wbr>6c</a><br>
<br>
And yes, I could successfully start Keycloak 2.1.0 on the migrated database.<br>
<br>
With that said, I agree with you that it would be a good idea to provide a script that only performs the database<br>
migration to ease testing of new releases.<br>
<br>
<br>
Cheers,<br>
Thomas<br>
<br>
</div></div>2016-08-18 20:54 GMT+02:00 Nalyvayko, Peter <<a href="mailto:pnalyvayko@agi.com">pnalyvayko@agi.com</a><mailto:<a href="mailto:pnalyvayko@agi.com">pna<wbr>lyvayko@agi.com</a>>>:<br>
<span class="">Tom, thanks for the link. My use case: the dev team uses keycloak final 2.0.0 release distribution in their development environment.<br>
To start keycloak they run 'standalone.bat' as a part of their dev test bootstrap (not 'mvn -f ...-Pkeycloak-server) . Sometimes there is a need to run the keycloak database init/upgrade without actually starting the keycloak server, so it would be great to be able to achieve that by specifying, for example, an extra parameter to'standalone.bat', i.e:<br>
<br>
$ standalone.bat --init-database-only<br>
<br>
The above command would execute the database initialization/upgrade and immediately terminate. Does it make sense?<br>
<br>
The instructions in the link, I believe, were written for a slightly different use case.<br>
<br>
______________________________<wbr>__________<br>
</span>From: Thomas Darimont [<a href="mailto:thomas.darimont@googlemail.com">thomas.darimont@googlemail.<wbr>com</a><mailto:<a href="mailto:thomas.darimont@googlemail.com">thomas.darimont@<wbr>googlemail.com</a>>]<br>
<span class="">Sent: Thursday, August 18, 2016 2:15 PM<br>
To: Nalyvayko, Peter<br>
Cc: keycloak-user<br>
Subject: Re: [keycloak-user] Database upgrade<br>
<br>
Hello Peter,<br>
<br>
<a href="https://github.com/keycloak/keycloak/blob/master/misc/UpdatingDatabaseSchema.md" rel="noreferrer" target="_blank">https://github.com/keycloak/<wbr>keycloak/blob/master/misc/<wbr>UpdatingDatabaseSchema.md</a><br>
<br>
Cheers,<br>
Thomas<br>
<br>
</span>2016-08-18 19:21 GMT+02:00 Nalyvayko, Peter <<a href="mailto:pnalyvayko@agi.com">pnalyvayko@agi.com</a><mailto:<a href="mailto:pnalyvayko@agi.com">pna<wbr>lyvayko@agi.com</a>><mailto:<a href="mailto:pnalyvayko@agi.com">pnalyv<wbr>ayko@agi.com</a><mailto:<a href="mailto:pnalyvayko@agi.com">pnalyvayko<wbr>@agi.com</a>>>>:<br>
<span class="">Hi,<br>
Is there an existing way to execute the keycloak database upgrade without actually starting the keycloak server?<br>
Thanks!<br>
--Peter<br>
______________________________<wbr>_________________<br>
keycloak-user mailing list<br>
</span><a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><<wbr>mailto:<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.<wbr>jboss.org</a>><mailto:<a href="mailto:keycloak-user@lists.jboss.org">keycloak-<wbr>user@lists.jboss.org</a><mailto:<a href="mailto:keycloak-user@lists.jboss.org">ke<wbr>ycloak-user@lists.jboss.org</a>>><br>
<span class=""><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/keycloak-user</a><br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
keycloak-user mailing list<br>
<a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
</span><a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/keycloak-user</a><br>
</blockquote></div><br></div>