-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add normalization to destination definition and actor definition table (
#18300) * updated StandardDestinationDefinition.yaml, added normalization and tags to the destination_definition.yaml and added information about normalization and DBT to the ACTOR_DEFINITION table * updated docs * updated BootloaderAppTest.java for new migration * updated schema dump * Update normalization version and fix bigquery * Use varchar 255 * Update migration version to the latest * Update normalized table schema file and add comment * Revert "Use varchar 255" This reverts commit e182466. * Use varchar 255 * Add unit test for migration * Format code Co-authored-by: Liren Tu <tuliren@gmail.com>
- Loading branch information
1 parent
15143f7
commit 350d544
Showing
10 changed files
with
178 additions
and
24 deletions.
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
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
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
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
51 changes: 51 additions & 0 deletions
51
...stance/configs/migrations/V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns.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,51 @@ | ||
/* | ||
* Copyright (c) 2022 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.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.jooq.impl.SQLDataType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns extends BaseJavaMigration { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns.class); | ||
|
||
@Override | ||
public void migrate(final Context context) throws Exception { | ||
LOGGER.info("Running migration: {}", this.getClass().getSimpleName()); | ||
final DSLContext ctx = DSL.using(context.getConnection()); | ||
addNormalizationRepositoryColumn(ctx); | ||
addNormalizationTagColumn(ctx); | ||
addSupportsDbtColumn(ctx); | ||
} | ||
|
||
static void addNormalizationRepositoryColumn(final DSLContext ctx) { | ||
ctx.alterTable("actor_definition") | ||
.addColumnIfNotExists(DSL.field( | ||
"normalization_repository", | ||
SQLDataType.VARCHAR(255).nullable(true))) | ||
.execute(); | ||
} | ||
|
||
static void addNormalizationTagColumn(final DSLContext ctx) { | ||
ctx.alterTable("actor_definition") | ||
.addColumnIfNotExists(DSL.field( | ||
"normalization_tag", | ||
SQLDataType.VARCHAR(255).nullable(true))) | ||
.execute(); | ||
} | ||
|
||
static void addSupportsDbtColumn(final DSLContext ctx) { | ||
ctx.alterTable("actor_definition") | ||
.addColumnIfNotExists(DSL.field("supports_dbt", | ||
SQLDataType.BOOLEAN.nullable(true))) | ||
.execute(); | ||
} | ||
|
||
} |
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
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
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
55 changes: 55 additions & 0 deletions
55
...ce/configs/migrations/V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumnsTest.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,55 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance.configs.migrations; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import io.airbyte.db.factory.FlywayFactory; | ||
import io.airbyte.db.instance.configs.AbstractConfigsDatabaseTest; | ||
import io.airbyte.db.instance.configs.ConfigsDatabaseMigrator; | ||
import io.airbyte.db.instance.development.DevDatabaseMigrator; | ||
import org.flywaydb.core.Flyway; | ||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.jooq.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumnsTest extends AbstractConfigsDatabaseTest { | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
final Flyway flyway = | ||
FlywayFactory.create(dataSource, "V0_40_18_001__AddInvalidProtocolFlagToConnections", ConfigsDatabaseMigrator.DB_IDENTIFIER, | ||
ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION); | ||
final ConfigsDatabaseMigrator configsDbMigrator = new ConfigsDatabaseMigrator(database, flyway); | ||
|
||
final BaseJavaMigration previousMigration = new V0_40_18_001__AddInvalidProtocolFlagToConnections(); | ||
final DevDatabaseMigrator devConfigsDbMigrator = new DevDatabaseMigrator(configsDbMigrator, previousMigration.getVersion()); | ||
devConfigsDbMigrator.createBaseline(); | ||
} | ||
|
||
@Test | ||
void test() throws Exception { | ||
final DSLContext context = getDslContext(); | ||
assertFalse(columnExists(context, "normalization_repository")); | ||
assertFalse(columnExists(context, "normalization_tag")); | ||
assertFalse(columnExists(context, "supports_dbt")); | ||
V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns.addNormalizationRepositoryColumn(context); | ||
assertTrue(columnExists(context, "normalization_repository")); | ||
V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns.addNormalizationTagColumn(context); | ||
assertTrue(columnExists(context, "normalization_tag")); | ||
V0_40_18_002__AddActorDefinitionNormalizationAndDbtColumns.addSupportsDbtColumn(context); | ||
assertTrue(columnExists(context, "supports_dbt")); | ||
} | ||
|
||
static boolean columnExists(final DSLContext ctx, final String columnName) { | ||
return ctx.fetchExists(DSL.select() | ||
.from("information_schema.columns") | ||
.where(DSL.field("table_name").eq("actor_definition") | ||
.and(DSL.field("column_name").eq(columnName)))); | ||
} | ||
|
||
} |
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