use of liquibase.statement.core.AddDefaultValueStatement in project liquibase by liquibase.
the class AddAutoIncrementChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
if (database instanceof PostgresDatabase) {
String sequenceName = (getTableName() + "_" + getColumnName() + "_seq");
String escapedTableName = database.escapeObjectName(getTableName(), Table.class);
String escapedColumnName = database.escapeObjectName(getColumnName(), Table.class);
if (escapedTableName != null && escapedColumnName != null && !escapedTableName.startsWith("\"") && !escapedColumnName.startsWith("\"")) {
sequenceName = sequenceName.toLowerCase();
}
String schemaPrefix;
if (this.schemaName == null) {
schemaPrefix = database.getDefaultSchemaName();
} else {
schemaPrefix = this.schemaName;
}
if (schemaPrefix == null) {
schemaPrefix = "";
} else {
schemaPrefix = schemaPrefix + ".";
}
return new SqlStatement[] { new CreateSequenceStatement(catalogName, this.schemaName, sequenceName), new SetNullableStatement(catalogName, this.schemaName, getTableName(), getColumnName(), null, false), new AddDefaultValueStatement(catalogName, this.schemaName, getTableName(), getColumnName(), getColumnDataType(), new SequenceNextValueFunction(schemaPrefix + sequenceName)) };
}
return new SqlStatement[] { new AddAutoIncrementStatement(getCatalogName(), getSchemaName(), getTableName(), getColumnName(), getColumnDataType(), getStartWith(), getIncrementBy()) };
}
use of liquibase.statement.core.AddDefaultValueStatement in project opennms by OpenNMS.
the class AddNamedAutoIncrementChange method generateStatements.
@Override
public SqlStatement[] generateStatements(final Database database) {
final List<SqlStatement> statements = new ArrayList<SqlStatement>();
if (database instanceof PostgresDatabase) {
String sequenceName = m_sequenceName;
if (m_sequenceName == null) {
sequenceName = (getTableName() + "_" + getColumnName() + "_seq").toLowerCase();
statements.add(new CreateSequenceStatement(getSchemaName(), sequenceName));
}
statements.add(new SetNullableStatement(getSchemaName(), getTableName(), getColumnName(), null, false));
statements.add(new AddDefaultValueStatement(getSchemaName(), getTableName(), getColumnName(), getColumnDataType(), new DatabaseFunction("NEXTVAL('" + sequenceName + "')")));
return statements.toArray(new SqlStatement[0]);
} else {
return super.generateStatements(database);
}
}
Aggregations