Search in sources :

Example 1 with SqlGenerator

use of liquibase.sqlgenerator.SqlGenerator in project liquibase by liquibase.

the class DropIndexGeneratorTest method shouldDropIndexInPostgreSQL.

// @Test
// public void execute_defaultSchema() throws Exception {
// new DatabaseTestTemplate().testOnAvailableDatabases(
// new SqlStatementDatabaseTest(null, new DropIndexStatement(IDX_NAME, null, TABLE_NAME)) {
// 
// protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// assertNotNull(snapshot.getIndex(IDX_NAME));
// }
// 
// protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// assertNull(snapshot.getIndex(IDX_NAME));
// }
// 
// });
// }
// 
// //todo: issues with schemas on some databases
// //    @Test
// //    public void execute_altSchema() throws Exception {
// //        new DatabaseTestTemplate().testOnAvailableDatabases(
// //                new SqlStatementDatabaseTest(TestContext.ALT_SCHEMA, new DropIndexStatement(ALT_IDX_NAME, TestContext.ALT_SCHEMA, TABLE_NAME)) {
// //
// //                    protected void preExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// //                        //todo: how do we assert indexes within a schema snapshot?
// ////                        assertNotNull(snapshot.getIndex(ALT_IDX_NAME));
// //                    }
// //
// //                    protected void postExecuteAssert(DatabaseSnapshotGenerator snapshot) {
// //                        //todo: how do we assert indexes within a schema snapshot?
// ////                        assertNull(snapshot.getIndex(ALT_IDX_NAME));
// //                    }
// //
// //                });
// //    }
@Test
public void shouldDropIndexInPostgreSQL() throws Exception {
    DropIndexGenerator dropIndexGenerator = new DropIndexGenerator();
    DropIndexStatement statement = new DropIndexStatement("indexName", "defaultCatalog", "defaultSchema", "aTable", null);
    Database database = new PostgresDatabase();
    SortedSet<SqlGenerator> sqlGenerators = new TreeSet<SqlGenerator>();
    SqlGeneratorChain sqlGenerationChain = new SqlGeneratorChain(sqlGenerators);
    Sql[] sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain);
    assertEquals("DROP INDEX \"defaultSchema\".\"indexName\"", sqls[0].toSql());
    statement = new DropIndexStatement("index_name", "default_catalog", "default_schema", "a_table", null);
    sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain);
    assertEquals("DROP INDEX default_schema.index_name", sqls[0].toSql());
    statement = new DropIndexStatement("index_name", null, null, "a_table", null);
    sqls = dropIndexGenerator.generateSql(statement, database, sqlGenerationChain);
    assertEquals("DROP INDEX index_name", sqls[0].toSql());
}
Also used : PostgresDatabase(liquibase.database.core.PostgresDatabase) SqlGenerator(liquibase.sqlgenerator.SqlGenerator) TreeSet(java.util.TreeSet) PostgresDatabase(liquibase.database.core.PostgresDatabase) Database(liquibase.database.Database) SqlGeneratorChain(liquibase.sqlgenerator.SqlGeneratorChain) DropIndexStatement(liquibase.statement.core.DropIndexStatement) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Example 2 with SqlGenerator

use of liquibase.sqlgenerator.SqlGenerator in project liquibase by liquibase.

the class AddDefaultValueGeneratorInformixTest method shouldGenerateINT8TypeForBIGINTAndDefaultValue.

@Test
public void shouldGenerateINT8TypeForBIGINTAndDefaultValue() throws Exception {
    AddDefaultValueGeneratorInformix informix = new AddDefaultValueGeneratorInformix();
    AddDefaultValueStatement statement = new AddDefaultValueStatement(null, null, "tbl1", "id", "BIGINT", 1);
    InformixDatabase database = new InformixDatabase();
    SortedSet<SqlGenerator> sqlGenerators = new TreeSet<SqlGenerator>();
    SqlGeneratorChain sqlGenerationChain = new SqlGeneratorChain(sqlGenerators);
    Sql[] sqls = informix.generateSql(statement, database, sqlGenerationChain);
    assertEquals("ALTER TABLE tbl1 MODIFY (id INT8 DEFAULT 1)", sqls[0].toSql());
}
Also used : InformixDatabase(liquibase.database.core.InformixDatabase) SqlGenerator(liquibase.sqlgenerator.SqlGenerator) TreeSet(java.util.TreeSet) AddDefaultValueStatement(liquibase.statement.core.AddDefaultValueStatement) SqlGeneratorChain(liquibase.sqlgenerator.SqlGeneratorChain) Sql(liquibase.sql.Sql) Test(org.junit.Test)

Aggregations

TreeSet (java.util.TreeSet)2 Sql (liquibase.sql.Sql)2 SqlGenerator (liquibase.sqlgenerator.SqlGenerator)2 SqlGeneratorChain (liquibase.sqlgenerator.SqlGeneratorChain)2 Test (org.junit.Test)2 Database (liquibase.database.Database)1 InformixDatabase (liquibase.database.core.InformixDatabase)1 PostgresDatabase (liquibase.database.core.PostgresDatabase)1 AddDefaultValueStatement (liquibase.statement.core.AddDefaultValueStatement)1 DropIndexStatement (liquibase.statement.core.DropIndexStatement)1