/**
  * 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.setCurrentSchema(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);
 }
Пример #2
0
  @Test
  public void multipleSetDataSourceCalls() throws Exception {
    DriverDataSource dataSource1 =
        new DriverDataSource(null, "jdbc:h2:mem:flyway_db_1;DB_CLOSE_DELAY=-1", "sa", "");

    DriverDataSource dataSource2 =
        new DriverDataSource(null, "jdbc:h2:mem:flyway_db_2;DB_CLOSE_DELAY=-1", "sa", "");

    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();
  }