Skip to content

Commit

Permalink
Fixed #598 No "current" schema in flyway.url causes a Flyway exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Fontaine committed Mar 4, 2015
1 parent 6116fec commit bd3d0ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ protected String doGetCurrentSchema() throws SQLException {

@Override
protected void doSetCurrentSchema(Schema schema) throws SQLException {
if ("".equals(schema.getName())) {
if (schema == null || "".equals(schema.getName())) {
try {
// Weird hack to switch back to no database selected...
String newDb = quote(UUID.randomUUID().toString());
jdbcTemplate.execute("CREATE SCHEMA " + newDb);
jdbcTemplate.execute("USE " + newDb);
jdbcTemplate.execute("DROP SCHEMA " + newDb);
} catch (Exception e) {
LOG.warn("Unable to restore connection to having no default schema");
LOG.warn("Unable to restore connection to having no default schema: " + e.getMessage());
}
} else {
jdbcTemplate.execute("USE " + schema);
jdbcTemplate.getConnection().setCatalog(schema.getName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ protected DataSource createDataSource(Properties customProperties) throws Except
}

@Test
public void migrateWithSchemaSetInPropertyButNotInUrl() throws Exception {
public void migrateWithNonExistingSchemaSetInPropertyButNotInUrl() throws Exception {
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:mysql://localhost/", "flyway", "flyway");
flyway.setSchemas("non-existant-schema");
flyway.setSchemas("non-existing-schema");
flyway.setLocations(BASEDIR);
flyway.clean();
assertEquals(4, flyway.migrate());
}

@Test
public void migrateWithExistingSchemaSetInPropertyButNotInUrl() throws Exception {
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:mysql://localhost/", "flyway", "flyway");
flyway.setSchemas("flyway_db");
flyway.setLocations(BASEDIR);
flyway.clean();
assertEquals(4, flyway.migrate());
Expand Down

0 comments on commit bd3d0ef

Please sign in to comment.