Skip to content

Commit

Permalink
Update FlywayFactory to support custom schema
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Collado <collado.mike@gmail.com>
  • Loading branch information
collado-mike committed Aug 2, 2022
1 parent 90feb2e commit 1bbb3db
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/src/main/java/marquez/db/FlywayFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.sql.DataSource;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.flywaydb.core.Flyway;

@NoArgsConstructor
Expand Down Expand Up @@ -74,6 +76,15 @@ public final class FlywayFactory {
@Getter @Setter
private String repeatableSqlMigrationPrefix = DEFAULT_REPEATABLE_SQL_MIGRATION_PREFIX;

@Getter private Optional<String> schema = Optional.empty();

public void setSchema(@NonNull String schema) {
if (StringUtils.isEmpty(schema)) {
throw new IllegalArgumentException("schema must not be blank");
}
this.schema = Optional.of(schema);
}

public Flyway build(@NonNull DataSource source) {
return Flyway.configure()
.dataSource(source)
Expand Down Expand Up @@ -102,6 +113,7 @@ public Flyway build(@NonNull DataSource source) {
.placeholderSuffix(placeholderSuffix)
.sqlMigrationPrefix(sqlMigrationPrefix)
.repeatableSqlMigrationPrefix(repeatableSqlMigrationPrefix)
.schemas(schema.map(s -> new String[] {s}).orElse(new String[] {}))
.load();
}
}

0 comments on commit 1bbb3db

Please sign in to comment.