-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a new string cloumn to configs for cron (#12416)
* 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
Showing
3 changed files
with
81 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
77 changes: 77 additions & 0 deletions
77
...io/airbyte/db/instance/configs/migrations/V0_36_3_001__AddScheduleTypeToConfigsTable.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,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; | ||
} | ||
|
||
} | ||
|
||
} |
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