Skip to content

Commit

Permalink
Migration: add failureSummary column to Attempts table in jobs da…
Browse files Browse the repository at this point in the history
…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
pmossman authored Jan 20, 2022
1 parent a007953 commit 4c83ac1
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
);
Expand Down
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"))));
}

}

0 comments on commit 4c83ac1

Please sign in to comment.