use of liquibase.sql.Sql in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementPostgresDatabase.
@Test
public void testAutoIncrementPostgresDatabase() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof PostgresDatabase) {
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (COLUMN1_NAME BIGSERIAL)", generatedSql[0].toSql());
}
}
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class CreateTableGeneratorTest method createReferencesSchemaEscaped.
@Test
public void createReferencesSchemaEscaped() throws Exception {
Database database = new PostgresDatabase();
database.setOutputDefaultSchema(true);
database.setDefaultSchemaName("my-schema");
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumnConstraint(new ForeignKeyConstraint("fk_test_parent", TABLE_NAME + "(id)").setColumn("id"));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE SCHEMA_NAME.TABLE_NAME (, CONSTRAINT fk_test_parent FOREIGN KEY (id) REFERENCES \"my-schema\".TABLE_NAME(id))", generatedSql[0].toSql());
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class CreateTableGeneratorTest method testAutoIncrementStartWithIncrementByDB2Database.
@Test
public void testAutoIncrementStartWithIncrementByDB2Database() throws Exception {
for (Database database : TestContext.getInstance().getAllDatabases()) {
if (database instanceof DB2Database) {
CreateTableStatement statement = new CreateTableStatement(CATALOG_NAME, SCHEMA_NAME, TABLE_NAME);
statement.addColumn(COLUMN_NAME1, DataTypeFactory.getInstance().fromDescription("BIGINT{autoIncrement:true}", database), new AutoIncrementConstraint(COLUMN_NAME1, BigInteger.ZERO, BigInteger.TEN));
Sql[] generatedSql = this.generatorUnderTest.generateSql(statement, database, null);
assertEquals("CREATE TABLE CATALOG_NAME.TABLE_NAME (COLUMN1_NAME BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 0, INCREMENT BY 10))", generatedSql[0].toSql());
}
}
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class SqlGeneratorChainTest method generateSql_oneGenerators.
@Test
public void generateSql_oneGenerators() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(1, "A1", "A2"));
SqlGeneratorChain chain = new SqlGeneratorChain(generators);
Sql[] sql = chain.generateSql(new MockSqlStatement(), new MockDatabase());
assertEquals(2, sql.length);
assertEquals("A1", sql[0].toSql());
assertEquals("A2", sql[1].toSql());
}
use of liquibase.sql.Sql in project liquibase by liquibase.
the class SqlGeneratorChainTest method generateSql_twoGenerators.
@Test
public void generateSql_twoGenerators() {
SortedSet<SqlGenerator> generators = new TreeSet<SqlGenerator>(new SqlGeneratorComparator());
generators.add(new MockSqlGenerator(2, "B1", "B2"));
generators.add(new MockSqlGenerator(1, "A1", "A2"));
SqlGeneratorChain chain = new SqlGeneratorChain(generators);
Sql[] sql = chain.generateSql(new MockSqlStatement(), new MockDatabase());
assertEquals(4, sql.length);
assertEquals("B1", sql[0].toSql());
assertEquals("B2", sql[1].toSql());
assertEquals("A1", sql[2].toSql());
assertEquals("A2", sql[3].toSql());
}
Aggregations