Search in sources :

Example 1 with SQLFileChange

use of liquibase.change.core.SQLFileChange in project quarkus by quarkusio.

the class LiquibaseMongodbProcessor method extractChangeFile.

private Optional<String> extractChangeFile(Change change, String changeSetFilePath) {
    String path = null;
    Boolean relative = null;
    if (change instanceof LoadDataChange) {
        LoadDataChange loadDataChange = (LoadDataChange) change;
        path = loadDataChange.getFile();
        relative = loadDataChange.isRelativeToChangelogFile();
    } else if (change instanceof SQLFileChange) {
        SQLFileChange sqlFileChange = (SQLFileChange) change;
        path = sqlFileChange.getPath();
        relative = sqlFileChange.isRelativeToChangelogFile();
    } else if (change instanceof CreateProcedureChange) {
        CreateProcedureChange createProcedureChange = (CreateProcedureChange) change;
        path = createProcedureChange.getPath();
        relative = createProcedureChange.isRelativeToChangelogFile();
    } else if (change instanceof CreateViewChange) {
        CreateViewChange createViewChange = (CreateViewChange) change;
        path = createViewChange.getPath();
        relative = createViewChange.getRelativeToChangelogFile();
    }
    // unrelated change or change does not reference a file (e.g. inline view)
    if (path == null) {
        return Optional.empty();
    }
    // absolute file path or changeSet has no file path
    if (relative == null || !relative || changeSetFilePath == null) {
        return Optional.of(path);
    }
    // notes: ClassLoaderResourceAccessor does not provide a suitable method and CLRA.getFinalPath() is not visible
    return Optional.of(Paths.get(changeSetFilePath).resolveSibling(path).toString().replace('\\', '/'));
}
Also used : SQLFileChange(liquibase.change.core.SQLFileChange) CreateViewChange(liquibase.change.core.CreateViewChange) CreateProcedureChange(liquibase.change.core.CreateProcedureChange) LoadDataChange(liquibase.change.core.LoadDataChange)

Example 2 with SQLFileChange

use of liquibase.change.core.SQLFileChange in project camunda-bpm-platform by camunda.

the class SqlScriptTest method executeSqlScript.

protected void executeSqlScript(String sqlFolder, String sqlScript) throws LiquibaseException {
    String statements = IoUtil.inputStreamAsString(getClass().getClassLoader().getResourceAsStream(String.format("sql/%s/%s_%s_%s.sql", sqlFolder, databaseType, sqlScript, projectVersion)));
    SQLFileChange sqlFileChange = new SQLFileChange();
    sqlFileChange.setSql(statements);
    database.execute(sqlFileChange.generateStatements(database), null);
}
Also used : SQLFileChange(liquibase.change.core.SQLFileChange)

Example 3 with SQLFileChange

use of liquibase.change.core.SQLFileChange in project quarkus by quarkusio.

the class LiquibaseProcessor method extractChangeFile.

private Optional<String> extractChangeFile(Change change, String changeSetFilePath) {
    String path = null;
    Boolean relative = null;
    if (change instanceof LoadDataChange) {
        LoadDataChange loadDataChange = (LoadDataChange) change;
        path = loadDataChange.getFile();
        relative = loadDataChange.isRelativeToChangelogFile();
    } else if (change instanceof SQLFileChange) {
        SQLFileChange sqlFileChange = (SQLFileChange) change;
        path = sqlFileChange.getPath();
        relative = sqlFileChange.isRelativeToChangelogFile();
    } else if (change instanceof CreateProcedureChange) {
        CreateProcedureChange createProcedureChange = (CreateProcedureChange) change;
        path = createProcedureChange.getPath();
        relative = createProcedureChange.isRelativeToChangelogFile();
    } else if (change instanceof CreateViewChange) {
        CreateViewChange createViewChange = (CreateViewChange) change;
        path = createViewChange.getPath();
        relative = createViewChange.getRelativeToChangelogFile();
    }
    // unrelated change or change does not reference a file (e.g. inline view)
    if (path == null) {
        return Optional.empty();
    }
    // absolute file path or changeSet has no file path
    if (relative == null || !relative || changeSetFilePath == null) {
        return Optional.of(path);
    }
    // notes: ClassLoaderResourceAccessor does not provide a suitable method and CLRA.getFinalPath() is not visible
    return Optional.of(Paths.get(changeSetFilePath).resolveSibling(path).toString().replace('\\', '/'));
}
Also used : SQLFileChange(liquibase.change.core.SQLFileChange) CreateViewChange(liquibase.change.core.CreateViewChange) CreateProcedureChange(liquibase.change.core.CreateProcedureChange) LoadDataChange(liquibase.change.core.LoadDataChange)

Example 4 with SQLFileChange

use of liquibase.change.core.SQLFileChange in project liquibase by liquibase.

the class RollbackVisitor method checkForEmptyRollbackFile.

private void checkForEmptyRollbackFile(ChangeSet changeSet) {
    RollbackContainer container = changeSet.getRollback();
    List<Change> changes = container.getChanges();
    if (changes.isEmpty()) {
        return;
    }
    for (Change change : changes) {
        if (!(change instanceof SQLFileChange)) {
            continue;
        }
        String sql = ((SQLFileChange) change).getSql();
        if (sql.length() == 0) {
            Scope.getCurrentScope().getLog(getClass()).info("\nNo rollback logic defined in empty rollback script. Changesets have been removed from\n" + "the DATABASECHANGELOG table but no other logic was performed.");
        }
    }
}
Also used : RollbackContainer(liquibase.changelog.RollbackContainer) SQLFileChange(liquibase.change.core.SQLFileChange) Change(liquibase.change.Change) SQLFileChange(liquibase.change.core.SQLFileChange)

Aggregations

SQLFileChange (liquibase.change.core.SQLFileChange)4 CreateProcedureChange (liquibase.change.core.CreateProcedureChange)2 CreateViewChange (liquibase.change.core.CreateViewChange)2 LoadDataChange (liquibase.change.core.LoadDataChange)2 Change (liquibase.change.Change)1 RollbackContainer (liquibase.changelog.RollbackContainer)1