Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres config 3605 #3862

Closed
wants to merge 7 commits into from
Closed

Postgres config 3605 #3862

wants to merge 7 commits into from

Conversation

masonwheeler
Copy link
Contributor

@masonwheeler masonwheeler commented Jun 3, 2021

Fixes #3605.

  • Adds a generic concept of database configuration persistence to Airbyte
  • Adds a Postgres-specific implementation of database config persistence
  • Changes the config persistence interface to formally use the UUID type, rather than String, for IDs that are supposed to always be in the form of a UUID
  • Adds tests for the Postgres Config Persistence class

@auto-assign auto-assign bot requested review from cgardens and jrhizor June 3, 2021 17:13
@masonwheeler masonwheeler requested review from michel-tricot, marcosmarxm and cgardens and removed request for jrhizor, cgardens and michel-tricot June 3, 2021 17:30
Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this incremental change. There are a handful of questions, but I think they are relatively straightforward.

I don't think this closes the issue yet, as we still need to figure out how to hook this up. That said I don't think there is anything breaking in this PR, so we can go ahead and merge it and then do the hook up part separately.

airbyte-config/db-persistence/build.gradle Outdated Show resolved Hide resolved
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by convention we try to avoid the XYZ.* imports (when you use the create test macro in intellij it does this automatically unfortunately. not sure how to get around it.)


// Create a table named CONFIG with three columns: CONFIG_ID (PK UUID/string), CONFIG_TYPE (string),
// CONFIG_DATA (JSON/string)
public abstract void Setup() throws SQLException;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> setup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when will this be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to be called by whatever code initializes the storage system for the first time, and also by the tests of course. That part isn't hooked up to any existing code yet other than the test.

}

public PostgresConfigPersistence(JsonNode config, JsonSchemaValidator validator) {
this(config.get("username").asText(), config.get("password").asText(), Databases.getPostgresJdbcUrl(config), validator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i appreciate the attempt to factor out this configuration component here, but I think this probably a place where we want to keep the code paths separate.

here's how i'm thinking about it... the config (a json blob) that we use in the postgres source, postgres destination, and the database that is used in airbyte-core are all different. at least in the case of source and destination, their configuration objects are declared separately.

this is to bringing to light one thing, which is putting these naked JsonNode in interfaces is kinda dangerous... they're almost no better than just doing type Object. this is a bit more tolerable in the connector world because (theoretically) the objects are validated (although as we discussed in your last PR, the tests don't check for it explicitly).

In general where possible we should reduce the use of just JsonNode, and I think in this case the schema of the object is knowable enough that we can do that.

@@ -116,4 +124,30 @@ default void executeWithinTransaction(List<String> queries) throws SQLException
CheckedFunction<ResultSet, T, SQLException> recordTransform)
throws SQLException;

default <T> Optional<T> querySingle(String sql, CheckedFunction<ResultSet, T, SQLException> recordTransform, String... params)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to call this executeParameterized and have it return a Stream<T>? after that you can still do a queryFirst or just in the consuming code fo the findFirst

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do that you might be able to use it in listConfigs.

jsonSchemaValidator = validator;
}

// Create a table named CONFIG with three columns: CONFIG_ID (PK UUID/string), CONFIG_TYPE (string),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is idiomatic in PG to use lower cased (snake cased) table names and column names.

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class DatabaseConfigPersistence implements ConfigPersistence {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this abstraction saving us all that much? i'm not super convinced it's getting us much over just having PostgresConfigPersistence. I guess we are mainly avoiding duplicating the get and list queries. it's probably little enough code that i would be just okay with duplicating.

it's just a guess on my part though, so please feel free to stick with this if you think it's worth it, but i wanted to share my perception.

@@ -109,4 +116,23 @@ private static BasicDataSource createBasicDataSource(final String username,
return connectionPool;
}

public static String getPostgresJdbcUrl(JsonNode config) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment below, but i don't think using JsonNode config here is very safe. It's hard to know if this is the config for pg source, pg destination, or something else.

@sherifnada sherifnada closed this Jul 30, 2021
@swyxio swyxio deleted the postgres_config_3605 branch October 11, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using a PG database for the config database
3 participants