use of liquibase.statement.core.AddAutoIncrementStatement 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.AddAutoIncrementStatement in project liquibase by liquibase.
the class AddAutoIncrementExecuteTest method noSchema.
@SuppressWarnings("unchecked")
@Test
public void noSchema() throws Exception {
this.statementUnderTest = new AddAutoIncrementStatement(null, null, TABLE_NAME, COLUMN_NAME, "int", null, null);
assertCorrect("alter table [table_name] modify column_name serial", PostgresDatabase.class);
assertCorrect("alter table table_name modify column_name int auto_increment", MySQLDatabase.class);
assertCorrect("ALTER TABLE [table_name] ALTER COLUMN [column_name] SET GENERATED BY DEFAULT AS IDENTITY", DB2Database.class);
assertCorrect("alter table table_name alter column column_name int generated by default as identity", HsqlDatabase.class, H2Database.class);
assertCorrect("ALTER TABLE [table_name] MODIFY [column_name] serial", InformixDatabase.class);
assertCorrect("ALTER TABLE [table_name] MODIFY [column_name] int default autoincrement", SybaseASADatabase.class);
assertCorrect("ALTER TABLE [table_name] MODIFY [column_name] int identity", SybaseDatabase.class);
assertCorrectOnRest("ALTER TABLE [table_name] MODIFY [column_name] int AUTO_INCREMENT");
}
use of liquibase.statement.core.AddAutoIncrementStatement in project liquibase by liquibase.
the class SqlGeneratorFactoryTest method getGenerators.
@Test
public void getGenerators() {
SortedSet<SqlGenerator> allGenerators = SqlGeneratorFactory.getInstance().getGenerators(new AddAutoIncrementStatement(null, null, "person", "name", "varchar(255)", null, null), new H2Database());
assertNotNull(allGenerators);
assertEquals(1, allGenerators.size());
}
Aggregations