}
@Override
public SqlStatement[] generateStatements(Database database) {
CreateTableStatement statement = generateCreateTableStatement();
for (ColumnConfig column : getColumns()) {
ConstraintsConfig constraints = column.getConstraints();
boolean isAutoIncrement = column.isAutoIncrement() != null && column.isAutoIncrement();
Object defaultValue = column.getDefaultValueObject();
LiquibaseDataType columnType = DataTypeFactory.getInstance().fromDescription(column.getType() + (isAutoIncrement ? "{autoIncrement:true}" : ""), database);
if (constraints != null && constraints.isPrimaryKey() != null && constraints.isPrimaryKey()) {
statement.addPrimaryKeyColumn(column.getName(), columnType, defaultValue, constraints.getPrimaryKeyName(), constraints.getPrimaryKeyTablespace());
} else {
statement.addColumn(column.getName(),
columnType,
defaultValue,
column.getRemarks());
}
if (constraints != null) {
if (constraints.isNullable() != null && !constraints.isNullable()) {
statement.addColumnConstraint(new NotNullConstraint(column.getName()));
}
if (constraints.getReferences() != null ||
(constraints.getReferencedTableName() != null && constraints.getReferencedColumnNames() != null)) {
if (StringUtils.trimToNull(constraints.getForeignKeyName()) == null) {
throw new UnexpectedLiquibaseException("createTable with references requires foreignKeyName");
}
ForeignKeyConstraint fkConstraint = new ForeignKeyConstraint(constraints.getForeignKeyName(),
constraints.getReferences(), constraints.getReferencedTableName(), constraints.getReferencedColumnNames());
fkConstraint.setColumn(column.getName());
fkConstraint.setDeleteCascade(constraints.isDeleteCascade() != null && constraints.isDeleteCascade());
fkConstraint.setInitiallyDeferred(constraints.isInitiallyDeferred() != null && constraints.isInitiallyDeferred());
fkConstraint.setDeferrable(constraints.isDeferrable() != null && constraints.isDeferrable());
statement.addColumnConstraint(fkConstraint);
}
if (constraints.isUnique() != null && constraints.isUnique()) {
statement.addColumnConstraint(new UniqueConstraint(constraints.getUniqueConstraintName()).addColumns(column.getName()));
}
}
if (isAutoIncrement) {
statement.addColumnConstraint(new AutoIncrementConstraint(column.getName(), column.getStartWith(), column.getIncrementBy()));
}
}
statement.setTablespace(StringUtils.trimToNull(getTablespace()));
List<SqlStatement> statements = new ArrayList<SqlStatement>();
statements.add(statement);
if (StringUtils.trimToNull(remarks) != null) {