Skip to content

Commit

Permalink
Add a new column in attempts table (#17806)
Browse files Browse the repository at this point in the history
* migration attempts

* migrator script

* version fix
  • Loading branch information
xiaohansong authored Oct 11, 2022
1 parent f5d339a commit fbead4d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void testBootloaderAppBlankDb() throws Exception {
bootloader.load();

val jobsMigrator = new JobsDatabaseMigrator(jobDatabase, jobsFlyway);
assertEquals("0.40.4.002", jobsMigrator.getLatestMigration().getVersion().getVersion());
assertEquals("0.40.14.001", jobsMigrator.getLatestMigration().getVersion().getVersion());

val configsMigrator = new ConfigsDatabaseMigrator(configDatabase, configsFlyway);
// this line should change with every new migration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 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;

// TODO: update migration description in the class name
public class V0_40_14_001__AddProcessingTaskQueueInAttempts extends BaseJavaMigration {

private static final Logger LOGGER = LoggerFactory.getLogger(
V0_40_14_001__AddProcessingTaskQueueInAttempts.class);

@Override
public void migrate(final Context context) throws Exception {
LOGGER.info("Running migration: {}", this.getClass().getSimpleName());

// Warning: please do not use any jOOQ generated code to write a migration.
// As database schema changes, the generated jOOQ code can be deprecated. So
// old migration may not compile if there is any generated code.
final DSLContext ctx = DSL.using(context.getConnection());
addProtocolVersionColumn(ctx);
}

private static void addProtocolVersionColumn(final DSLContext ctx) {
ctx.alterTable("attempts")
.addColumnIfNotExists(DSL.field(
"processing_task_queue",
SQLDataType.VARCHAR(255).nullable(true)))
.execute();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ create table "public"."attempts"(
"ended_at" timestamptz(35) null,
"temporal_workflow_id" varchar(256) null,
"failure_summary" jsonb null,
"processing_task_queue" varchar(255) null,
constraint "attempts_pkey"
primary key ("id")
);
Expand Down

0 comments on commit fbead4d

Please sign in to comment.