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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations