Skip to content

Commit

Permalink
feat!: add columns for fork in builder feature to `connector_builder_…
Browse files Browse the repository at this point in the history
…project` (#13597)
  • Loading branch information
Ella Rohm-Ensing committed Aug 21, 2024
1 parent 546c4d1 commit 3e09d86
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class BootloaderTest {

// ⚠️ This line should change with every new migration to show that you meant to make a new
// migration to the prod database
private static final String CURRENT_CONFIGS_MIGRATION_VERSION = "0.57.4.015";
private static final String CURRENT_CONFIGS_MIGRATION_VERSION = "0.57.4.016";
private static final String CURRENT_JOBS_MIGRATION_VERSION = "0.57.2.005";

@BeforeEach
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2020-2024 Airbyte, Inc., all rights reserved.
*/

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

import static org.jooq.impl.DSL.constraint;

import java.util.UUID;
import org.flywaydb.core.api.migration.BaseJavaMigration;
import org.flywaydb.core.api.migration.Context;
import org.jooq.DSLContext;
import org.jooq.Field;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class V0_57_4_016__AddBaseActorDefVersionAndContributionColumnsToConnectorBuilderProject extends BaseJavaMigration {

private static final Logger LOGGER = LoggerFactory.getLogger(
V0_57_4_016__AddBaseActorDefVersionAndContributionColumnsToConnectorBuilderProject.class);
private static final String CONNECTOR_BUILDER_PROJECT_TABLE = "connector_builder_project";

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

final DSLContext ctx = DSL.using(context.getConnection());
addBaseActorDefinitionVersionIdToConnectorBuilderProject(ctx);
addContributionPullRequestUrlToConnectorBuilderProject(ctx);
addContributionActorDefinitionIdToConnectorBuilderProject(ctx);
}

private static void addBaseActorDefinitionVersionIdToConnectorBuilderProject(final DSLContext ctx) {
final Field<UUID> defaultVersionId = DSL.field("base_actor_definition_version_id", SQLDataType.UUID.nullable(true));

ctx.alterTable(CONNECTOR_BUILDER_PROJECT_TABLE).addIfNotExists(defaultVersionId).execute();
ctx.alterTable(CONNECTOR_BUILDER_PROJECT_TABLE)
.add(constraint("connector_builder_project_base_adv_id_fkey").foreignKey(defaultVersionId)
.references("actor_definition_version", "id").onDeleteRestrict())
.execute();
}

private static void addContributionPullRequestUrlToConnectorBuilderProject(final DSLContext ctx) {
final Field<String> pullRequestUrl = DSL.field("contribution_pull_request_url", SQLDataType.VARCHAR(256).nullable(true));
ctx.alterTable(CONNECTOR_BUILDER_PROJECT_TABLE).addIfNotExists(pullRequestUrl).execute();
}

private static void addContributionActorDefinitionIdToConnectorBuilderProject(final DSLContext ctx) {
// This is not a foreign key because this is a reference to the actor definition that will be in the
// catalog upon publish. In other words, the reference will resolve for forked connectors,
// but will not resolve for new connectors until their publish is successful.
final Field<UUID> pullRequestUrl = DSL.field("contribution_actor_definition_id", SQLDataType.UUID.nullable(true));
ctx.alterTable(CONNECTOR_BUILDER_PROJECT_TABLE).addIfNotExists(pullRequestUrl).execute();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ create table "public"."connector_builder_project" (
"created_at" timestamp(6) with time zone not null default current_timestamp,
"updated_at" timestamp(6) with time zone not null default current_timestamp,
"testing_values" jsonb,
"base_actor_definition_version_id" uuid,
"contribution_pull_request_url" varchar(256),
"contribution_actor_definition_id" uuid,
constraint "connector_builder_project_pkey" primary key ("id")
);
create table "public"."declarative_manifest" (
Expand Down Expand Up @@ -520,6 +523,7 @@ alter table "public"."connection_operation" add constraint "connection_operation
alter table "public"."connection_operation" add constraint "connection_operation_operation_id_fkey" foreign key ("operation_id") references "public"."operation" ("id");
alter table "public"."connection_timeline_event" add constraint "connection_timeline_event_connection_id_fkey" foreign key ("connection_id") references "public"."connection" ("id");
alter table "public"."connection_timeline_event" add constraint "connection_timeline_event_user_id_fkey" foreign key ("user_id") references "public"."user" ("id");
alter table "public"."connector_builder_project" add constraint "connector_builder_project_base_adv_id_fkey" foreign key ("base_actor_definition_version_id") references "public"."actor_definition_version" ("id");
alter table "public"."notification_configuration" add constraint "notification_configuration_connection_id_fkey" foreign key ("connection_id") references "public"."connection" ("id");
alter table "public"."operation" add constraint "operation_workspace_id_fkey" foreign key ("workspace_id") references "public"."workspace" ("id");
alter table "public"."organization_email_domain" add constraint "organization_email_domain_organization_id_fkey" foreign key ("organization_id") references "public"."organization" ("id");
Expand Down

0 comments on commit 3e09d86

Please sign in to comment.