use of io.quarkus.liquibase.LiquibaseFactory in project quarkus by quarkusio.
the class LiquibaseRecorder method doStartActions.
public void doStartActions() {
try {
InjectableInstance<LiquibaseFactory> liquibaseFactoryInstance = Arc.container().select(LiquibaseFactory.class, Any.Literal.INSTANCE);
if (liquibaseFactoryInstance.isUnsatisfied()) {
return;
}
for (InstanceHandle<LiquibaseFactory> liquibaseFactoryHandle : liquibaseFactoryInstance.handles()) {
try {
LiquibaseFactory liquibaseFactory = liquibaseFactoryHandle.get();
var config = liquibaseFactory.getConfiguration();
if (!config.cleanAtStart && !config.migrateAtStart) {
continue;
}
try (Liquibase liquibase = liquibaseFactory.createLiquibase()) {
if (config.cleanAtStart) {
liquibase.dropAll();
}
if (config.migrateAtStart) {
if (config.validateOnMigrate) {
liquibase.validate();
}
liquibase.update(liquibaseFactory.createContexts(), liquibaseFactory.createLabels());
}
}
} catch (UnsatisfiedResolutionException e) {
// ignore, the DS is not configured
}
}
} catch (Exception e) {
throw new IllegalStateException("Error starting Liquibase", e);
}
}
use of io.quarkus.liquibase.LiquibaseFactory in project quarkus by quarkusio.
the class LiquibaseSchemaProvider method resetAllDatabases.
@Override
public void resetAllDatabases() {
try {
InjectableInstance<LiquibaseFactory> liquibaseFactoryInstance = Arc.container().select(LiquibaseFactory.class, Any.Literal.INSTANCE);
if (liquibaseFactoryInstance.isUnsatisfied()) {
return;
}
for (InstanceHandle<LiquibaseFactory> liquibaseFactoryHandle : liquibaseFactoryInstance.handles()) {
try {
LiquibaseFactory liquibaseFactory = liquibaseFactoryHandle.get();
doReset(liquibaseFactory);
} catch (UnsatisfiedResolutionException e) {
// ignore, the DS is not configured
}
}
} catch (Exception e) {
throw new IllegalStateException("Error starting Liquibase", e);
}
}
use of io.quarkus.liquibase.LiquibaseFactory in project quarkus by quarkusio.
the class LiquibaseDevConsoleRecorder method handler.
public Handler<RoutingContext> handler() {
return new DevConsolePostHandler() {
@Override
protected void handlePost(RoutingContext event, MultiMap form) throws Exception {
String datasource = form.get("datasource");
String operation = form.get("operation");
InjectableInstance<LiquibaseFactory> liquibaseFactoryInstance = Arc.container().select(LiquibaseFactory.class);
if (liquibaseFactoryInstance.isUnsatisfied()) {
return;
}
Annotation qualifier;
if (DataSourceUtil.isDefault(datasource)) {
qualifier = Default.Literal.INSTANCE;
} else {
qualifier = LiquibaseDataSourceLiteral.of(datasource);
}
InstanceHandle<LiquibaseFactory> liquibaseFactoryHandle = Arc.container().instance(LiquibaseFactory.class, qualifier);
if (!liquibaseFactoryHandle.isAvailable()) {
flashMessage(event, "Unknown datasource: " + datasource, FlashMessageStatus.ERROR);
}
LiquibaseFactory liquibaseFactory = liquibaseFactoryHandle.get();
if ("clean".equals(operation)) {
try (Liquibase liquibase = liquibaseFactory.createLiquibase()) {
liquibase.dropAll();
}
flashMessage(event, "Datasource " + datasource + " cleaned");
return;
} else if ("migrate".equals(operation)) {
try (Liquibase liquibase = liquibaseFactory.createLiquibase()) {
liquibase.update(liquibaseFactory.createContexts(), liquibaseFactory.createLabels());
}
flashMessage(event, "Datasource " + datasource + " migrated");
return;
} else {
flashMessage(event, "Invalid operation: " + operation, FlashMessageStatus.ERROR);
return;
}
}
};
}
use of io.quarkus.liquibase.LiquibaseFactory in project quarkus by quarkusio.
the class LiquibaseRecorder method liquibaseSupplier.
public Supplier<LiquibaseFactory> liquibaseSupplier(String dataSourceName) {
DataSource dataSource = DataSources.fromName(dataSourceName);
if (dataSource instanceof UnconfiguredDataSource) {
return new Supplier<LiquibaseFactory>() {
@Override
public LiquibaseFactory get() {
throw new UnsatisfiedResolutionException("No datasource has been configured");
}
};
}
LiquibaseFactoryProducer liquibaseProducer = Arc.container().instance(LiquibaseFactoryProducer.class).get();
LiquibaseFactory liquibaseFactory = liquibaseProducer.createLiquibaseFactory(dataSource, dataSourceName);
return new Supplier<LiquibaseFactory>() {
@Override
public LiquibaseFactory get() {
return liquibaseFactory;
}
};
}
Aggregations