Skip to content

Commit

Permalink
Add db identifier to fix migration file directory (airbytehq#5851)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliren authored Sep 6, 2021
1 parent 71a96f5 commit 8b62fb2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class ConfigsDatabaseMigrationDevCenter extends MigrationDevCenter {

public ConfigsDatabaseMigrationDevCenter() {
super("src/main/resources/configs_database/schema_dump.txt");
super("configs", "src/main/resources/configs_database/schema_dump.txt");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ private enum Command {
DUMP_SCHEMA
}

/**
* Directory under which a new migration will be created. This should match the database's name and
* match the {@link Db} enum. Set in main to enforce correct implementation.
*/
private static String migrationDirectory;

private final String dbIdentifier;
private final String schemaDumpFile;

protected MigrationDevCenter(String schemaDumpFile) {
protected MigrationDevCenter(String dbIdentifier, String schemaDumpFile) {
this.dbIdentifier = dbIdentifier;
this.schemaDumpFile = schemaDumpFile;
}

Expand All @@ -75,7 +71,7 @@ private static PostgreSQLContainer<?> createContainer() {
private void createMigration() {
try (PostgreSQLContainer<?> container = createContainer(); Database database = getDatabase(container)) {
FlywayDatabaseMigrator migrator = getMigrator(database);
MigrationDevHelper.createNextMigrationFile(migrationDirectory, migrator);
MigrationDevHelper.createNextMigrationFile(dbIdentifier, migrator);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -109,14 +105,8 @@ public static void main(String[] args) {

Db db = Db.valueOf(args[0].toUpperCase());
switch (db) {
case CONFIGS -> {
devCenter = new ConfigsDatabaseMigrationDevCenter();
migrationDirectory = "configs";
}
case JOBS -> {
devCenter = new JobsDatabaseMigrationDevCenter();
migrationDirectory = "jobs";
}
case CONFIGS -> devCenter = new ConfigsDatabaseMigrationDevCenter();
case JOBS -> devCenter = new JobsDatabaseMigrationDevCenter();
default -> throw new IllegalArgumentException("Unexpected database: " + args[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class JobsDatabaseMigrationDevCenter extends MigrationDevCenter {

public JobsDatabaseMigrationDevCenter() {
super("src/main/resources/jobs_database/schema_dump.txt");
super("jobs", "src/main/resources/jobs_database/schema_dump.txt");
}

@Override
Expand Down

0 comments on commit 8b62fb2

Please sign in to comment.