forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration: add
failureSummary
column to Attempts
table in jobs da…
…tabase (airbytehq#9579) * Add migration to add failures column to Attempts table * rename column from failures to failureSummary * add missing copyright * update latest migration version in test
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_Attempts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance.jobs.migrations; | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.jooq.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.jooq.impl.SQLDataType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class V0_35_5_001__Add_failureSummary_col_to_Attempts extends BaseJavaMigration { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(V0_35_5_001__Add_failureSummary_col_to_Attempts.class); | ||
|
||
@Override | ||
public void migrate(final Context context) throws Exception { | ||
LOGGER.info("Running migration: {}", this.getClass().getSimpleName()); | ||
|
||
final DSLContext ctx = DSL.using(context.getConnection()); | ||
addFailureSummaryColumn(ctx); | ||
} | ||
|
||
public static void addFailureSummaryColumn(final DSLContext ctx) { | ||
ctx.alterTable("attempts") | ||
.addColumnIfNotExists(DSL.field("failure_summary", SQLDataType.JSONB.nullable(true))) | ||
.execute(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...byte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_AttemptsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance.jobs.migrations; | ||
|
||
import io.airbyte.db.Database; | ||
import io.airbyte.db.instance.jobs.AbstractJobsDatabaseTest; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import org.jooq.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class V0_35_5_001__Add_failureSummary_col_to_AttemptsTest extends AbstractJobsDatabaseTest { | ||
|
||
@Test | ||
public void test() throws SQLException, IOException { | ||
final Database database = getDatabase(); | ||
final DSLContext context = DSL.using(database.getDataSource().getConnection()); | ||
Assertions.assertFalse(failureSummaryColumnExists(context)); | ||
V0_35_5_001__Add_failureSummary_col_to_Attempts.addFailureSummaryColumn(context); | ||
Assertions.assertTrue(failureSummaryColumnExists(context)); | ||
} | ||
|
||
protected static boolean failureSummaryColumnExists(final DSLContext ctx) { | ||
return ctx.fetchExists(DSL.select() | ||
.from("information_schema.columns") | ||
.where(DSL.field("table_name").eq("attempts") | ||
.and(DSL.field("column_name").eq("failure_summary")))); | ||
} | ||
|
||
} |