Search in sources :

Example 6 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class AddColumnGenerator method validateSingleColumn.

private ValidationErrors validateSingleColumn(AddColumnStatement statement, Database database) {
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("columnName", statement.getColumnName());
    validationErrors.checkRequiredField("columnType", statement.getColumnType());
    validationErrors.checkRequiredField("tableName", statement.getTableName());
    if (statement.isPrimaryKey() && (database instanceof H2Database || database instanceof DB2Database || database instanceof DerbyDatabase || database instanceof SQLiteDatabase)) {
        validationErrors.addError("Cannot add a primary key column");
    }
    // TODO HsqlDatabase autoincrement on non primary key? other databases?
    if (database instanceof MySQLDatabase && statement.isAutoIncrement() && !statement.isPrimaryKey()) {
        validationErrors.addError("Cannot add a non-primary key identity column");
    }
    // TODO is this feature valid for other databases?
    if ((statement.getAddAfterColumn() != null) && !(database instanceof MySQLDatabase)) {
        validationErrors.addError("Cannot add column on specific position");
    }
    if ((statement.getAddBeforeColumn() != null) && !((database instanceof H2Database) || (database instanceof HsqlDatabase))) {
        validationErrors.addError("Cannot add column on specific position");
    }
    if ((statement.getAddAtPosition() != null) && !(database instanceof FirebirdDatabase)) {
        validationErrors.addError("Cannot add column on specific position");
    }
    return validationErrors;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Example 7 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class AddDefaultValueGenerator method validate.

@Override
public ValidationErrors validate(AddDefaultValueStatement addDefaultValueStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    Object defaultValue = addDefaultValueStatement.getDefaultValue();
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("defaultValue", defaultValue);
    validationErrors.checkRequiredField("columnName", addDefaultValueStatement.getColumnName());
    validationErrors.checkRequiredField("tableName", addDefaultValueStatement.getTableName());
    if (!database.supportsSequences() && defaultValue instanceof SequenceNextValueFunction) {
        validationErrors.addError("Database " + database.getShortName() + " does not support sequences");
    }
    if (database instanceof HsqlDatabase) {
        if (defaultValue instanceof SequenceNextValueFunction) {
            validationErrors.addError("Database " + database.getShortName() + " does not support adding sequence-based default values");
        } else if (defaultValue instanceof DatabaseFunction && !HsqlDatabase.supportsDefaultValueComputed(addDefaultValueStatement.getColumnDataType(), defaultValue.toString())) {
            validationErrors.addError("Database " + database.getShortName() + " does not support adding function-based default values");
        }
    }
    String columnDataType = addDefaultValueStatement.getColumnDataType();
    if (columnDataType != null) {
        LiquibaseDataType dataType = DataTypeFactory.getInstance().fromDescription(columnDataType, database);
        boolean typeMismatch = false;
        if (dataType instanceof BooleanType) {
            if (!(defaultValue instanceof Boolean)) {
                typeMismatch = true;
            }
        } else if (dataType instanceof CharType) {
            if (!(defaultValue instanceof String) && !(defaultValue instanceof DatabaseFunction)) {
                typeMismatch = true;
            }
        }
        if (typeMismatch) {
            validationErrors.addError("Default value of " + defaultValue + " does not match defined type of " + columnDataType);
        }
    }
    return validationErrors;
}
Also used : HsqlDatabase(liquibase.database.core.HsqlDatabase) DatabaseFunction(liquibase.statement.DatabaseFunction) ValidationErrors(liquibase.exception.ValidationErrors) LiquibaseDataType(liquibase.datatype.LiquibaseDataType) BooleanType(liquibase.datatype.core.BooleanType) SequenceNextValueFunction(liquibase.statement.SequenceNextValueFunction) CharType(liquibase.datatype.core.CharType)

Example 8 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class AddUniqueConstraintGenerator method validate.

@Override
public ValidationErrors validate(AddUniqueConstraintStatement addUniqueConstraintStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("columnNames", addUniqueConstraintStatement.getColumnNames());
    validationErrors.checkRequiredField("tableName", addUniqueConstraintStatement.getTableName());
    if (!(database instanceof OracleDatabase)) {
        validationErrors.checkDisallowedField("forIndexName", addUniqueConstraintStatement.getForIndexName(), database);
    }
    if (!(database instanceof MSSQLDatabase) && addUniqueConstraintStatement.isClustered()) {
        validationErrors.checkDisallowedField("clustered", addUniqueConstraintStatement.isClustered(), database);
    }
    return validationErrors;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Example 9 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class FindForeignKeyConstraintsGeneratorMSSQL method validate.

@Override
public ValidationErrors validate(FindForeignKeyConstraintsStatement findForeignKeyConstraintsStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("baseTableName", findForeignKeyConstraintsStatement.getBaseTableName());
    return validationErrors;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Example 10 with ValidationErrors

use of liquibase.exception.ValidationErrors in project liquibase by liquibase.

the class FindForeignKeyConstraintsGeneratorPostgres method validate.

@Override
public ValidationErrors validate(FindForeignKeyConstraintsStatement findForeignKeyConstraintsStatement, Database database, SqlGeneratorChain sqlGeneratorChain) {
    ValidationErrors validationErrors = new ValidationErrors();
    validationErrors.checkRequiredField("baseTableName", findForeignKeyConstraintsStatement.getBaseTableName());
    return validationErrors;
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors)

Aggregations

ValidationErrors (liquibase.exception.ValidationErrors)89 Test (org.junit.Test)11 MockDatabase (liquibase.sdk.database.MockDatabase)9 Database (liquibase.database.Database)6 MockSqlStatement (liquibase.statement.core.MockSqlStatement)6 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)2 Change (liquibase.change.Change)2 ChangeFactory (liquibase.change.ChangeFactory)2 ChangeMetaData (liquibase.change.ChangeMetaData)2 ChangeParameterMetaData (liquibase.change.ChangeParameterMetaData)2 CreateTableChange (liquibase.change.core.CreateTableChange)2 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)2 RanChangeSet (liquibase.changelog.RanChangeSet)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 SqlStatement (liquibase.statement.SqlStatement)2 AddColumnStatement (liquibase.statement.core.AddColumnStatement)2 JUnitResourceAccessor (liquibase.test.JUnitResourceAccessor)2 AbstractVerifyTest (liquibase.verify.AbstractVerifyTest)2 Ignore (org.junit.Ignore)2