Skip to content

Commit

Permalink
Adds a new string cloumn to configs for cron (#12416)
Browse files Browse the repository at this point in the history
* Adds a new string cloumn to configs for cron

closes #11418
i'm new to this task in Java please be brutal

* Adds airbyte header

* WIP

* Rebase a week of commits

* WIP for davin

* deps update

* Reorganize code for better readability. Also add a schema.

* Update tests.

* Correct bad test.

* Adds note for testing version change

* formatting change

Co-authored-by: Davin Chia <[email protected]>
  • Loading branch information
2 people authored and suhomud committed May 23, 2022
1 parent 8b15796 commit 54483e6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ void testBootloaderAppBlankDb() throws Exception {

val configDatabase = new ConfigsDatabaseInstance(configsDslContext).getAndInitialize();
val configsMigrator = new ConfigsDatabaseMigrator(configDatabase, configsFlyway);
assertEquals("0.35.65.001", configsMigrator.getLatestMigration().getVersion().getVersion());
// this line should change with every new migration
// to show that you meant to make a new migration to the prod database
assertEquals("0.36.3.001", configsMigrator.getLatestMigration().getVersion().getVersion());

val jobsPersistence = new DefaultJobPersistence(jobDatabase);
assertEquals(version, jobsPersistence.getVersion().get());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2021 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.db.instance.configs.migrations;

import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.jooq.Catalog;
import org.jooq.DSLContext;
import org.jooq.EnumType;
import org.jooq.Schema;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.SchemaImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class V0_36_3_001__AddScheduleTypeToConfigsTable extends BaseJavaMigration {

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

@Override
public void migrate(final Context context) throws Exception {
LOGGER.info("Running migration: {}", this.getClass().getSimpleName());
final DSLContext ctx = DSL.using(context.getConnection());
createScheduleTypeEnum(ctx);
addPublicColumn(ctx);
}

private static void createScheduleTypeEnum(final DSLContext ctx) {
ctx.createType("schedule_type").asEnum("manual", "basic_schedule", "cron").execute();
}

private static void addPublicColumn(final DSLContext ctx) {
ctx.alterTable("connection")
.addColumnIfNotExists(DSL.field(
"schedule_type",
SQLDataType.VARCHAR.asEnumDataType(ScheduleType.class).nullable(true)))
.execute();
}

public enum ScheduleType implements EnumType {

manual("manual"),
basicSchedule("basic_schedule"),
cron("cron"),;

private final String literal;

ScheduleType(final String literal) {
this.literal = literal;
}

@Override
public Catalog getCatalog() {
return getSchema() == null ? null : getSchema().getCatalog();
}

@Override
public Schema getSchema() {
return new SchemaImpl(DSL.name("public"), null);
}

@Override
public String getName() {
return "schedule_type";
}

@Override
public String getLiteral() {
return literal;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ create table "public"."connection"(
"created_at" timestamptz(35) not null default null,
"updated_at" timestamptz(35) not null default null,
"source_catalog_id" uuid null,
"schedule_type" schedule_type null,
constraint "connection_pkey"
primary key ("id")
);
Expand Down

0 comments on commit 54483e6

Please sign in to comment.