use of liquibase.statement.core.SetNullableStatement 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.SetNullableStatement in project liquibase by liquibase.
the class AddNotNullConstraintChange method generateStatements.
@Override
public SqlStatement[] generateStatements(Database database) {
//// if (database instanceof SQLiteDatabase) {
// // return special statements for SQLite databases
// return generateStatementsForSQLiteDatabase(database);
// }
List<SqlStatement> statements = new ArrayList<SqlStatement>();
if (defaultNullValue != null) {
statements.add(new UpdateStatement(getCatalogName(), getSchemaName(), getTableName()).addNewColumnValue(getColumnName(), defaultNullValue).setWhereClause(database.escapeObjectName(getColumnName(), Column.class) + " IS NULL"));
}
statements.add(new SetNullableStatement(getCatalogName(), getSchemaName(), getTableName(), getColumnName(), getColumnDataType(), false, getConstraintName()));
if (database instanceof DB2Database) {
statements.add(new ReorganizeTableStatement(getCatalogName(), getSchemaName(), getTableName()));
}
return statements.toArray(new SqlStatement[statements.size()]);
}
use of liquibase.statement.core.SetNullableStatement in project liquibase by liquibase.
the class SetNullableGeneratorTest method testGenerateOracleNotNullSql.
@Test
public void testGenerateOracleNotNullSql() throws Exception {
final Sql[] sqls = generator.generateSql(new SetNullableStatement(null, "schema_name", "table_name", "column_name", null, false), oracle, null);
assertEquals(1, sqls.length);
final Sql sql = sqls[0];
assertEquals("ALTER TABLE schema_name.table_name MODIFY column_name NOT NULL", sql.toSql());
}
use of liquibase.statement.core.SetNullableStatement 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);
}
}
use of liquibase.statement.core.SetNullableStatement in project liquibase by liquibase.
the class SetNullableGeneratorTest method testGenerateOracleNotNullSqlWithConstraintName.
@Test
public void testGenerateOracleNotNullSqlWithConstraintName() throws Exception {
final Sql[] sqls = generator.generateSql(new SetNullableStatement(null, "schema_name", "table_name", "column_name", null, false, "constraint_name"), oracle, null);
assertEquals(1, sqls.length);
final Sql sql = sqls[0];
assertEquals("ALTER TABLE schema_name.table_name MODIFY column_name CONSTRAINT constraint_name NOT NULL", sql.toSql());
}
Aggregations