Search in sources :

Example 1 with Schema

use of org.flywaydb.core.internal.dbsupport.Schema in project flyway by flyway.

the class DB2zOSMigrationMediumTest method isSchemaEmpty.

/**
     * Override isSchemaEmpty. Setting schema and table space in SQL.
     *
     * @throws Exception
     */
@Override
@Test
public void isSchemaEmpty() throws Exception {
    Schema schema = dbSupport.getSchema("AURINT");
    assertTrue(schema.empty());
    flyway.setLocations(getMigrationDir());
    flyway.baseline();
    flyway.migrate();
    assertFalse(schema.empty());
    flyway.clean();
    assertTrue(schema.empty());
}
Also used : Schema(org.flywaydb.core.internal.dbsupport.Schema) Test(org.junit.Test)

Example 2 with Schema

use of org.flywaydb.core.internal.dbsupport.Schema in project flyway by flyway.

the class DB2zOSMigrationMediumTest method setCurrentSchema.

/**
     * Override schema test. DB2 on zOS does not support "Create schema"
     *
     * @throws Exception
     */
@Override
@Test(expected = UnsupportedOperationException.class)
public void setCurrentSchema() throws Exception {
    Schema schema = dbSupport.getSchema("current_schema_test");
    try {
        schema.create();
        flyway.setSchemas("current_schema_test");
        flyway.clean();
        flyway.setLocations("migration/current_schema");
        Map<String, String> placeholders = new HashMap<String, String>();
        placeholders.put("schema1", dbSupport.quote("current_schema_test"));
        flyway.setPlaceholders(placeholders);
        flyway.migrate();
    } finally {
        schema.drop();
    }
}
Also used : HashMap(java.util.HashMap) Schema(org.flywaydb.core.internal.dbsupport.Schema) Test(org.junit.Test)

Example 3 with Schema

use of org.flywaydb.core.internal.dbsupport.Schema in project flyway by flyway.

the class EnterpriseDBDbSupportMediumTest method setCurrentSchema.

/**
     * Checks that the search_path is extended and not overwritten so that objects in PUBLIC can still be found.
     */
@Test
public void setCurrentSchema() throws Exception {
    Connection connection = createDataSource().getConnection();
    PostgreSQLDbSupport dbSupport = new PostgreSQLDbSupport(connection);
    Schema schema = dbSupport.getSchema("search_path_test");
    schema.create();
    dbSupport.changeCurrentSchemaTo(dbSupport.getSchema("search_path_test"));
    String searchPath = dbSupport.getJdbcTemplate().queryForString("SHOW search_path");
    assertEquals("search_path_test, \"$user\", public", searchPath);
    schema.drop();
    JdbcUtils.closeConnection(connection);
}
Also used : Schema(org.flywaydb.core.internal.dbsupport.Schema) Connection(java.sql.Connection) PostgreSQLDbSupport(org.flywaydb.core.internal.dbsupport.postgresql.PostgreSQLDbSupport) Test(org.junit.Test)

Example 4 with Schema

use of org.flywaydb.core.internal.dbsupport.Schema in project flyway by flyway.

the class HsqlMigrationMediumTest method view.

@Test
public void view() throws Exception {
    Schema schema = dbSupport.getSchema("MY_VIEWS");
    schema.create();
    flyway.setSchemas("PUBLIC", "MY_VIEWS");
    flyway.setLocations("migration/dbsupport/hsql/sql/view");
    flyway.migrate();
    flyway.clean();
    schema.drop();
}
Also used : Schema(org.flywaydb.core.internal.dbsupport.Schema) Test(org.junit.Test)

Example 5 with Schema

use of org.flywaydb.core.internal.dbsupport.Schema in project flyway by flyway.

the class FlywayMediumTest method multipleSetDataSourceCalls.

@Test
public void multipleSetDataSourceCalls() throws Exception {
    DriverDataSource dataSource1 = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_1;DB_CLOSE_DELAY=-1", "sa", "", null);
    DriverDataSource dataSource2 = new DriverDataSource(Thread.currentThread().getContextClassLoader(), null, "jdbc:h2:mem:flyway_db_2;DB_CLOSE_DELAY=-1", "sa", "", null);
    Connection connection1 = dataSource1.getConnection();
    Connection connection2 = dataSource2.getConnection();
    Schema schema1 = new H2DbSupport(connection1).getSchema("PUBLIC");
    Schema schema2 = new H2DbSupport(connection2).getSchema("PUBLIC");
    assertTrue(schema1.empty());
    assertTrue(schema2.empty());
    Flyway flyway = new Flyway();
    flyway.setDataSource(dataSource1);
    flyway.setDataSource(dataSource2);
    flyway.setLocations("migration/sql");
    flyway.migrate();
    assertTrue(schema1.empty());
    assertFalse(schema2.empty());
    connection1.close();
    connection2.close();
}
Also used : H2DbSupport(org.flywaydb.core.internal.dbsupport.h2.H2DbSupport) DriverDataSource(org.flywaydb.core.internal.util.jdbc.DriverDataSource) Schema(org.flywaydb.core.internal.dbsupport.Schema) Connection(java.sql.Connection) Test(org.junit.Test)

Aggregations

Schema (org.flywaydb.core.internal.dbsupport.Schema)16 Test (org.junit.Test)13 Connection (java.sql.Connection)8 FlywayException (org.flywaydb.core.api.FlywayException)4 FlywayCallback (org.flywaydb.core.api.callback.FlywayCallback)4 SQLException (java.sql.SQLException)3 MigrationResolver (org.flywaydb.core.api.resolver.MigrationResolver)3 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)3 MetaDataTable (org.flywaydb.core.internal.metadatatable.MetaDataTable)3 HashMap (java.util.HashMap)2 SqlScriptFlywayCallback (org.flywaydb.core.internal.callback.SqlScriptFlywayCallback)2 FlywaySqlScriptException (org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException)2 SqlScript (org.flywaydb.core.internal.dbsupport.SqlScript)2 CompositeMigrationResolver (org.flywaydb.core.internal.resolver.CompositeMigrationResolver)2 TransactionTemplate (org.flywaydb.core.internal.util.jdbc.TransactionTemplate)2 ClassPathResource (org.flywaydb.core.internal.util.scanner.classpath.ClassPathResource)2 LinkedHashSet (java.util.LinkedHashSet)1 Properties (java.util.Properties)1 Callable (java.util.concurrent.Callable)1 MigrationInfoService (org.flywaydb.core.api.MigrationInfoService)1