forked from Archives/Athou_commafeed
upgrade to liquibase 3.0.1 (#351)
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -175,7 +175,7 @@
|
||||
<dependency>
|
||||
<groupId>org.liquibase</groupId>
|
||||
<artifactId>liquibase-core</artifactId>
|
||||
<version>2.0.5</version>
|
||||
<version>3.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
46
src/main/java/liquibase/integration/cdi/CDIBootstrap.java
Normal file
46
src/main/java/liquibase/integration/cdi/CDIBootstrap.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package liquibase.integration.cdi;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.enterprise.event.Observes;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.enterprise.inject.spi.AfterBeanDiscovery;
|
||||
import javax.enterprise.inject.spi.AfterDeploymentValidation;
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.Extension;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import liquibase.integration.cdi.annotations.LiquibaseType;
|
||||
import liquibase.resource.ResourceAccessor;
|
||||
|
||||
/**
|
||||
* temporary fix until https://liquibase.jira.com/browse/CORE-1325 is fixed
|
||||
*/
|
||||
public class CDIBootstrap implements Extension {
|
||||
|
||||
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
|
||||
}
|
||||
|
||||
void afterDeploymentValidation(@Observes AfterDeploymentValidation event,
|
||||
BeanManager manager) {
|
||||
}
|
||||
|
||||
@Produces
|
||||
@LiquibaseType
|
||||
public CDILiquibaseConfig createConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Produces
|
||||
@LiquibaseType
|
||||
public DataSource createDataSource() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Produces
|
||||
@LiquibaseType
|
||||
public ResourceAccessor create() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package liquibase.precondition.core;
|
||||
|
||||
import liquibase.changelog.DatabaseChangeLog;
|
||||
import liquibase.changelog.ChangeSet;
|
||||
import liquibase.database.Database;
|
||||
import liquibase.snapshot.SnapshotGeneratorFactory;
|
||||
import liquibase.structure.core.Column;
|
||||
import liquibase.structure.core.Index;
|
||||
import liquibase.structure.core.Schema;
|
||||
import liquibase.exception.*;
|
||||
import liquibase.precondition.Precondition;
|
||||
import liquibase.structure.core.Table;
|
||||
import liquibase.util.StringUtils;
|
||||
|
||||
/**
|
||||
* fix for https://github.com/liquibase/liquibase/commit/30934beeb45fd50a1c33bb0cacc089157936ec95#commitcomment-3519020
|
||||
*/
|
||||
public class IndexExistsPrecondition implements Precondition {
|
||||
private String catalogName;
|
||||
private String schemaName;
|
||||
private String tableName;
|
||||
private String columnNames;
|
||||
private String indexName;
|
||||
|
||||
public String getCatalogName() {
|
||||
return catalogName;
|
||||
}
|
||||
|
||||
public void setCatalogName(String catalogName) {
|
||||
this.catalogName = catalogName;
|
||||
}
|
||||
|
||||
public String getSchemaName() {
|
||||
return schemaName;
|
||||
}
|
||||
|
||||
public void setSchemaName(String schemaName) {
|
||||
this.schemaName = schemaName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
public void setTableName(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getIndexName() {
|
||||
return indexName;
|
||||
}
|
||||
|
||||
public void setIndexName(String indexName) {
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
public String getColumnNames() {
|
||||
return columnNames;
|
||||
}
|
||||
|
||||
public void setColumnNames(String columnNames) {
|
||||
this.columnNames = columnNames;
|
||||
}
|
||||
|
||||
public Warnings warn(Database database) {
|
||||
return new Warnings();
|
||||
}
|
||||
|
||||
public ValidationErrors validate(Database database) {
|
||||
ValidationErrors validationErrors = new ValidationErrors();
|
||||
if (getIndexName() == null && getTableName() == null && getColumnNames() == null) {
|
||||
validationErrors.addError("indexName OR tableName and columnNames is required");
|
||||
}
|
||||
return validationErrors;
|
||||
}
|
||||
|
||||
public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet) throws PreconditionFailedException, PreconditionErrorException {
|
||||
try {
|
||||
Schema schema = new Schema(getCatalogName(), getSchemaName());
|
||||
Index example = new Index();
|
||||
example.setTable(new Table());
|
||||
if (StringUtils.trimToNull(getTableName()) != null) {
|
||||
example.getTable().setName(database.correctObjectName(getTableName(), Table.class));
|
||||
}
|
||||
example.getTable().setSchema(schema);
|
||||
example.setName(database.correctObjectName(getIndexName(), Index.class));
|
||||
if (StringUtils.trimToNull(getColumnNames()) != null) {
|
||||
for (String column : getColumnNames().split("\\s*,\\s*")) {
|
||||
example.getColumns().add(database.correctObjectName(column, Column.class));
|
||||
}
|
||||
}
|
||||
if (!SnapshotGeneratorFactory.getInstance().has(example, database)) {
|
||||
String name = "";
|
||||
|
||||
if (getIndexName() != null) {
|
||||
name += database.escapeStringForDatabase(getIndexName());
|
||||
}
|
||||
|
||||
if (StringUtils.trimToNull(getTableName()) != null) {
|
||||
name += " on "+database.escapeStringForDatabase(getTableName());
|
||||
|
||||
if (StringUtils.trimToNull(getColumnNames()) != null) {
|
||||
name += " columns "+getColumnNames();
|
||||
}
|
||||
}
|
||||
throw new PreconditionFailedException("Index "+ name +" does not exist", changeLog, this);
|
||||
}
|
||||
} catch (PreconditionFailedException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new PreconditionErrorException(e, changeLog, this);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "indexExists";
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
|
||||
|
||||
<changeSet author="athou" id="init">
|
||||
<preConditions onFail="MARK_RAN" onFailMessage="Existing database, skipping initial schema setup">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
|
||||
|
||||
<changeSet author="athou" id="recreate-fes-index">
|
||||
<preConditions onFail="MARK_RAN" onFailMessage="index already exists">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
|
||||
|
||||
<include file="changelogs/db.changelog-1.0.xml" />
|
||||
<include file="changelogs/db.changelog-1.1.xml" />
|
||||
|
||||
Reference in New Issue
Block a user