Skip to content

Commit 30dad41

Browse files
committed
wip
1 parent 1597e73 commit 30dad41

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

airbyte-config/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.jooq.Record2;
8181
import org.jooq.Result;
8282
import org.jooq.SelectJoinStep;
83+
import org.jooq.Table;
8384
import org.jooq.impl.DSL;
8485
import org.slf4j.Logger;
8586
import org.slf4j.LoggerFactory;
@@ -90,8 +91,9 @@ public class ConfigRepository {
9091
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRepository.class);
9192
private static final String OPERATION_IDS_AGG_FIELD = "operation_ids_agg";
9293
private static final String OPERATION_IDS_AGG_DELIMITER = ",";
94+
public static final String PRIMARY_KEY = "id";
9395

94-
// private final ConfigPersistence persistence;
96+
// private final ConfigPersistence persistence;
9597
private final ExceptionWrappingDatabase database;
9698
private final ActorDefinitionMigrator actorDefinitionMigrator;
9799

@@ -337,13 +339,22 @@ public void writeCustomSourceDefinition(final StandardSourceDefinition sourceDef
337339
}
338340

339341
public void deleteStandardSourceDefinition(final UUID sourceDefId) throws IOException {
340-
try {
341-
persistence.deleteConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, sourceDefId.toString());
342-
} catch (final ConfigNotFoundException e) {
342+
if(!deleteById(ACTOR_DEFINITION, sourceDefId)) {
343343
LOGGER.info("Attempted to delete source definition with id: {}, but it does not exist", sourceDefId);
344344
}
345345
}
346346

347+
/**
348+
* Deletes all records with given id. If it deletes anything, returns true. Otherwise, false.
349+
* @param table - table from which to delete the record
350+
* @param id - id of the record to delete
351+
* @return true if anything was deleted, otherwise false.
352+
* @throws IOException - you never know when you io
353+
*/
354+
private boolean deleteById(final Table<?> table, final UUID id) throws IOException {
355+
return database.transaction(ctx -> ctx.deleteFrom(table)).where(DSL.field(DSL.name(PRIMARY_KEY)).eq(id)).execute() > 0;
356+
}
357+
347358
public void deleteSourceDefinitionAndAssociations(final UUID sourceDefinitionId)
348359
throws JsonValidationException, ConfigNotFoundException, IOException {
349360
deleteConnectorDefinitionAndAssociations(
@@ -476,8 +487,7 @@ public void deleteDestinationDefinitionAndAssociations(final UUID destinationDef
476487
destinationDefinitionId);
477488
}
478489

479-
private <T> void deleteConnectorDefinitionAndAssociations(
480-
final ConfigSchema definitionType,
490+
private <T> void deleteConnectorDefinitionAndAssociations(final ConfigSchema definitionType,
481491
final ConfigSchema connectorType,
482492
final Class<T> connectorClass,
483493
final Function<T, UUID> connectorIdGetter,

0 commit comments

Comments
 (0)