KEYCLOAK-1181 Running Liquibase updates via maven plugin doesn't work
This commit is contained in:
parent
d0ead0f0a0
commit
2ba2e7768d
3 changed files with 21 additions and 2 deletions
|
@ -38,7 +38,11 @@
|
||||||
<groupId>org.jboss.logging</groupId>
|
<groupId>org.jboss.logging</groupId>
|
||||||
<artifactId>jboss-logging</artifactId>
|
<artifactId>jboss-logging</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.keycloak</groupId>
|
||||||
|
<artifactId>keycloak-services</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -15,14 +15,18 @@ import liquibase.resource.ResourceAccessor;
|
||||||
import liquibase.snapshot.SnapshotGeneratorFactory;
|
import liquibase.snapshot.SnapshotGeneratorFactory;
|
||||||
import liquibase.statement.SqlStatement;
|
import liquibase.statement.SqlStatement;
|
||||||
import liquibase.structure.core.Table;
|
import liquibase.structure.core.Table;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
import org.keycloak.connections.jpa.updater.liquibase.ThreadLocalSessionContext;
|
import org.keycloak.connections.jpa.updater.liquibase.ThreadLocalSessionContext;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.services.DefaultKeycloakSessionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||||
*/
|
*/
|
||||||
public abstract class CustomKeycloakTask implements CustomSqlChange {
|
public abstract class CustomKeycloakTask implements CustomSqlChange {
|
||||||
|
|
||||||
|
private final Logger logger = Logger.getLogger(getClass());
|
||||||
|
|
||||||
protected KeycloakSession kcSession;
|
protected KeycloakSession kcSession;
|
||||||
|
|
||||||
protected Database database;
|
protected Database database;
|
||||||
|
@ -49,8 +53,18 @@ public abstract class CustomKeycloakTask implements CustomSqlChange {
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws SetupException {
|
public void setUp() throws SetupException {
|
||||||
this.kcSession = ThreadLocalSessionContext.getCurrentSession();
|
this.kcSession = ThreadLocalSessionContext.getCurrentSession();
|
||||||
|
|
||||||
if (this.kcSession == null) {
|
if (this.kcSession == null) {
|
||||||
throw new SetupException("No KeycloakSession provided in ThreadLocal");
|
// Probably running Liquibase from maven plugin. Try to create kcSession programmatically
|
||||||
|
logger.info("No KeycloakSession provided in ThreadLocal. Initializing KeycloakSessionFactory");
|
||||||
|
|
||||||
|
try {
|
||||||
|
DefaultKeycloakSessionFactory factory = new DefaultKeycloakSessionFactory();
|
||||||
|
factory.init();
|
||||||
|
this.kcSession = factory.create();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SetupException("Exception when initializing factory", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<module name="org.keycloak.keycloak-core"/>
|
<module name="org.keycloak.keycloak-core"/>
|
||||||
<module name="org.keycloak.keycloak-model-api"/>
|
<module name="org.keycloak.keycloak-model-api"/>
|
||||||
<module name="org.keycloak.keycloak-connections-jpa"/>
|
<module name="org.keycloak.keycloak-connections-jpa"/>
|
||||||
|
<module name="org.keycloak.keycloak-services"/>
|
||||||
<module name="org.liquibase"/>
|
<module name="org.liquibase"/>
|
||||||
<module name="javax.persistence.api"/>
|
<module name="javax.persistence.api"/>
|
||||||
<module name="org.jboss.logging"/>
|
<module name="org.jboss.logging"/>
|
||||||
|
|
Loading…
Reference in a new issue