Skip to content

Commit

Permalink
Replace configuration with a new version, identical to v2. (#295)
Browse files Browse the repository at this point in the history
### What

This introduces configuration version 3, and removes versions 1 and 2.

This is most definitely a breaking change, and we're not done. Future
changes will tear this apart and rebuild it, but I wanted to make this
part easier to review.

### How

I did this in a few steps to make sure I didn't break anything.

1. I pulled out some of the lower-level configuration types to their own
files.
2. Next, I copied the remaining shared code from v1 to v2 so there were
no cross-dependencies.
3. Then I copied v2 to v3, and modified all the tests to use a v3 config
(identical to v2 except the `"version"` field).
4. Finally, I removed v1 and v2.
  • Loading branch information
SamirTalwar authored Feb 14, 2024
1 parent 6ee371e commit 121ec33
Show file tree
Hide file tree
Showing 57 changed files with 2,199 additions and 50,810 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/cargo-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,8 @@ jobs:
env:
AURORA_CONNECTION_STRING: ${{ secrets.AURORA_CONNECTION_STRING }}
run: |
# take connection string from env, create NDC metadata file with it
cat static/aurora/v1-chinook-ndc-metadata-template.json \
| jq '.connectionUri={"uri":{"value":(env | .AURORA_CONNECTION_STRING)}}' \
> static/aurora/v1-chinook-ndc-metadata.json
cat static/aurora/v2-chinook-ndc-metadata-template.json \
| jq '.connectionUri={"uri":{"value":(env | .AURORA_CONNECTION_STRING)}}' \
> static/aurora/v2-chinook-ndc-metadata.json
jq '.connectionUri = {"uri": {"value": (env | .AURORA_CONNECTION_STRING)}}' static/aurora/v3-chinook-ndc-metadata-template.json \
> static/aurora/v3-chinook-ndc-metadata.json
- name: install tools
run: |
Expand Down
93 changes: 34 additions & 59 deletions crates/configuration/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,21 @@ use ndc_sdk::connector;

use query_engine_metadata::metadata;

use crate::custom_trait_implementations::RawConfigurationCompat;
use crate::version1;
use crate::version2;
use crate::values::{ConnectionUri, IsolationLevel, PoolSettings, ResolvedSecret};
use crate::version3;

/// Initial configuration, just enough to connect to a database and elaborate a full
/// 'Configuration'.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(tag = "version")]
#[serde(try_from = "RawConfigurationCompat")]
#[serde(into = "RawConfigurationCompat")]
// NOTE: Any changes to this data type will need follow-up changes to the
// 'custom_trait_implementations' module.
pub enum RawConfiguration {
// Until https://github.com/serde-rs/serde/pull/2525 is merged enum tags have to be strings.
#[serde(rename = "1")]
Version1(version1::RawConfiguration),
#[serde(rename = "2")]
Version2(version2::RawConfiguration),
#[serde(rename = "3")]
Version3(version3::RawConfiguration),
}

impl RawConfiguration {
pub fn empty() -> Self {
RawConfiguration::Version2(version2::RawConfiguration::empty())
RawConfiguration::Version3(version3::RawConfiguration::empty())
}
}

Expand All @@ -43,26 +35,20 @@ pub struct Configuration {
}

pub async fn configure(
args: RawConfiguration,
input: RawConfiguration,
) -> Result<RawConfiguration, connector::UpdateConfigurationError> {
match args {
RawConfiguration::Version1(v1) => {
Ok(RawConfiguration::Version1(version1::configure(v1).await?))
}
RawConfiguration::Version2(v2) => {
Ok(RawConfiguration::Version2(version2::configure(v2).await?))
}
match input {
RawConfiguration::Version3(config) => Ok(RawConfiguration::Version3(
version3::configure(config).await?,
)),
}
}
pub async fn validate_raw_configuration(
config: RawConfiguration,
input: RawConfiguration,
) -> Result<Configuration, connector::ValidateError> {
match config {
RawConfiguration::Version1(v1) => Ok(Configuration {
config: RawConfiguration::Version1(version1::validate_raw_configuration(v1).await?),
}),
RawConfiguration::Version2(v2) => Ok(Configuration {
config: RawConfiguration::Version2(version2::validate_raw_configuration(v2).await?),
match input {
RawConfiguration::Version3(config) => Ok(Configuration {
config: RawConfiguration::Version3(version3::validate_raw_configuration(config).await?),
}),
}
}
Expand All @@ -79,47 +65,36 @@ pub async fn validate_raw_configuration(
#[derive(Debug)]
pub struct RuntimeConfiguration<'request> {
pub metadata: Cow<'request, metadata::Metadata>,
pub pool_settings: &'request version2::PoolSettings,
pub pool_settings: &'request PoolSettings,
pub connection_uri: &'request str,
pub isolation_level: version2::IsolationLevel,
pub isolation_level: IsolationLevel,
pub mutations_version: Option<metadata::mutations::MutationsVersion>,
}

/// Apply the common interpretations on the Configuration API type into an RuntimeConfiguration.
pub fn as_runtime_configuration(config: &Configuration) -> RuntimeConfiguration<'_> {
match &config.config {
RawConfiguration::Version1(v1) => RuntimeConfiguration {
metadata: Cow::Owned(version1::metadata_to_current(&v1.metadata)),
pool_settings: &v1.pool_settings,
connection_uri: match &v1.connection_uri {
version1::ConnectionUri::Uri(version1::ResolvedSecret(uri)) => uri,
},
isolation_level: version2::IsolationLevel::default(),
mutations_version: None,
},
RawConfiguration::Version2(v2) => RuntimeConfiguration {
metadata: Cow::Borrowed(&v2.metadata),
pool_settings: &v2.pool_settings,
connection_uri: match &v2.connection_uri {
version2::ConnectionUri::Uri(version2::ResolvedSecret(uri)) => uri,
pub fn as_runtime_configuration(input: &Configuration) -> RuntimeConfiguration<'_> {
match &input.config {
RawConfiguration::Version3(config) => RuntimeConfiguration {
metadata: Cow::Borrowed(&config.metadata),
pool_settings: &config.pool_settings,
connection_uri: match &config.connection_uri {
ConnectionUri::Uri(ResolvedSecret(uri)) => uri,
},
isolation_level: v2.isolation_level,
mutations_version: v2.configure_options.mutations_version,
isolation_level: config.isolation_level,
mutations_version: config.configure_options.mutations_version,
},
}
}

// for tests

pub fn set_connection_uri(config: RawConfiguration, connection_uri: String) -> RawConfiguration {
match config {
RawConfiguration::Version1(v1) => RawConfiguration::Version1(version1::RawConfiguration {
connection_uri: version1::ConnectionUri::Uri(version1::ResolvedSecret(connection_uri)),
..v1
}),
RawConfiguration::Version2(v2) => RawConfiguration::Version2(version2::RawConfiguration {
connection_uri: version2::ConnectionUri::Uri(version2::ResolvedSecret(connection_uri)),
..v2
}),
pub fn set_connection_uri(input: RawConfiguration, connection_uri: String) -> RawConfiguration {
match input {
RawConfiguration::Version3(config) => {
RawConfiguration::Version3(version3::RawConfiguration {
connection_uri: ConnectionUri::Uri(ResolvedSecret(connection_uri)),
..config
})
}
}
}
199 changes: 0 additions & 199 deletions crates/configuration/src/custom_trait_implementations.rs

This file was deleted.

11 changes: 5 additions & 6 deletions crates/configuration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
mod configuration;
mod custom_trait_implementations;
pub mod version1;
pub mod version2;
mod values;

pub mod version3;

pub use configuration::{
as_runtime_configuration, configure, set_connection_uri, validate_raw_configuration,
Configuration, RawConfiguration, RuntimeConfiguration,
};
pub use version2::{
occurring_scalar_types, ConnectionUri, IsolationLevel, PoolSettings, ResolvedSecret,
};
pub use values::{ConnectionUri, IsolationLevel, PoolSettings, ResolvedSecret};
pub use version3::occurring_scalar_types;
Loading

0 comments on commit 121ec33

Please sign in to comment.