From 4c83ac1f16d4eb839eda0a2fdacddb867a70fcc0 Mon Sep 17 00:00:00 2001 From: Parker Mossman Date: Thu, 20 Jan 2022 14:21:52 -0800 Subject: [PATCH] Migration: add `failureSummary` column to `Attempts` table in jobs database (#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 --- .../airbyte/bootloader/BootloaderAppTest.java | 2 +- ...1__Add_failureSummary_col_to_Attempts.java | 33 ++++++++++++++++++ .../resources/jobs_database/schema_dump.txt | 1 + ...dd_failureSummary_col_to_AttemptsTest.java | 34 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 airbyte-db/lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_Attempts.java create mode 100644 airbyte-db/lib/src/test/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_AttemptsTest.java diff --git a/airbyte-bootloader/src/test/java/io/airbyte/bootloader/BootloaderAppTest.java b/airbyte-bootloader/src/test/java/io/airbyte/bootloader/BootloaderAppTest.java index 9f3da9177372..18ccdf2fc1ff 100644 --- a/airbyte-bootloader/src/test/java/io/airbyte/bootloader/BootloaderAppTest.java +++ b/airbyte-bootloader/src/test/java/io/airbyte/bootloader/BootloaderAppTest.java @@ -68,7 +68,7 @@ void testBootloaderAppBlankDb() throws Exception { container.getPassword(), container.getJdbcUrl()).getInitialized(); val jobsMigrator = new JobsDatabaseMigrator(jobDatabase, this.getClass().getName()); - assertEquals("0.29.15.001", jobsMigrator.getLatestMigration().getVersion().getVersion()); + assertEquals("0.35.5.001", jobsMigrator.getLatestMigration().getVersion().getVersion()); val configDatabase = new ConfigsDatabaseInstance( mockedConfigs.getConfigDatabaseUser(), diff --git a/airbyte-db/lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_Attempts.java b/airbyte-db/lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_Attempts.java new file mode 100644 index 000000000000..6bb63405b632 --- /dev/null +++ b/airbyte-db/lib/src/main/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_Attempts.java @@ -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(); + } + +} diff --git a/airbyte-db/lib/src/main/resources/jobs_database/schema_dump.txt b/airbyte-db/lib/src/main/resources/jobs_database/schema_dump.txt index 32657bdf7af1..f15611ab47cb 100644 --- a/airbyte-db/lib/src/main/resources/jobs_database/schema_dump.txt +++ b/airbyte-db/lib/src/main/resources/jobs_database/schema_dump.txt @@ -33,6 +33,7 @@ create table "public"."attempts"( "updated_at" timestamptz(35) null, "ended_at" timestamptz(35) null, "temporal_workflow_id" varchar(256) null, + "failure_summary" jsonb null, constraint "attempts_pkey" primary key ("id") ); diff --git a/airbyte-db/lib/src/test/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_AttemptsTest.java b/airbyte-db/lib/src/test/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_AttemptsTest.java new file mode 100644 index 000000000000..94b79480346f --- /dev/null +++ b/airbyte-db/lib/src/test/java/io/airbyte/db/instance/jobs/migrations/V0_35_5_001__Add_failureSummary_col_to_AttemptsTest.java @@ -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")))); + } + +}