Skip to content

config v5 with native operations rename #522

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

Merged
merged 12 commits into from
Jul 10, 2024

Conversation

soupi
Copy link
Contributor

@soupi soupi commented Jul 5, 2024

What

We introduce ndc-postgres configuration version "v5".

This version changes two things:

  1. Renames the field nativeQueries to nativeOperations, and instead of containing native queries and native mutations together with a flag on each marking if it is mutation or not (isProcedure), we nest the in different objects, so we have:

    nativeOperations:
      queries:
      mutations:
    
  2. We nest scalarTypes and compositeTypes under one field, types:

    types:
      scalar:
      composite:
    

How

Might be useful to read as commits.

We first copy paste v4 to v5, then create types for Types and NativeOperations which nest the other information, then we fix all the relevant things: ndc-spec schema, cli handling, upgrading from older configs, conversion to runtime config, etc.

Then we fix the tests, including introducing new configs and changing the paths the the configs.

Then we get rid of the older configurations in the static/<db> directories, as they are not longer used for anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste from v4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste from v4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste from v4.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy paste from v4.

Comment on lines +21 to +23
pub types: Types,
#[serde(default)]
pub native_operations: NativeOperations,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these two are different.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fairly straightforward because they are almost the same shape.

Comment on lines +138 to +160
fn upgrade_native_queries(
native_queries: version4::metadata::NativeQueries,
) -> metadata::NativeOperations {
let version4::metadata::NativeQueries(native_queries_map) = native_queries;

let mut queries = BTreeMap::new();
let mut mutations = BTreeMap::new();

for (name, native_query_info) in native_queries_map {
let is_procedure = native_query_info.is_procedure;
let operation = upgrade_native_query_info(native_query_info);
if is_procedure {
mutations.insert(name, operation);
} else {
queries.insert(name, operation);
}
}

metadata::NativeOperations {
queries: metadata::NativeQueries(queries),
mutations: metadata::NativeQueries(mutations),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pretty much the only part this is interesting in the file.

Comment on lines -287 to 320
pub fn lookup_native_query(
pub fn lookup_native_mutation(
&self,
procedure_name: &str,
) -> Result<&metadata::NativeQueryInfo, Error> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

only used by mutations anyway, hinted by the argument named procedure_name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We didn't switch all of the translation tests to work against version 4. Perhaps we should, but we also have coverage from the db tests.

Comment on lines +41 to +48
"types": {
"scalar": {},
"composite": {}
},
"nativeOperations": {
"queries": {},
"mutations": {}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The change.

@soupi soupi marked this pull request as ready for review July 9, 2024 13:00
@soupi soupi requested a review from plcplc July 9, 2024 13:34
Comment on lines +97 to +101
MultiError(vec![
("Trying V3".to_string(), Box::new(v3_err)),
("Trying V4".to_string(), Box::new(v4_err)),
("Trying V5".to_string(), Box::new(v5_err)),
]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have a "version" field we can go on here to differentiate before trying to parse the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there's a hidden assumption here that we might not have the same configuration structure in later versions.

For example, if one version calls the configuration file configuration.json and the other config.json, then we need to ask each version module, how to get the config version.

Might be worth thinking about, perhaps when @plcplc returns, but for now let's continue with this way of doing things and improve it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good point; we don't know how it will continue.

} {
entry.insert(new_native_operation);
} else {
anyhow::bail!("A Native Operation with the name '{}' already exists. To override, use the --override flag.", name);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
anyhow::bail!("A Native Operation with the name '{}' already exists. To override, use the --override flag.", name);
anyhow::bail!("A Native Operation with the name '{name}' already exists. To override, use the --override flag.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 3 to 9
// This code was copied from a different place that predated the introduction of clippy to the
// project. Therefore we disregard certain clippy lints:
#![allow(
clippy::enum_variant_names,
clippy::upper_case_acronyms,
clippy::wrong_self_convention
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels appropriate to fix these when making breaking changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Comment on lines 3 to 5
// This code was copied from a different place that predated the introduction of clippy to the
// project. Therefore we disregard certain clippy lints:
#![allow(clippy::wrong_self_convention)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

self.metadata
.composite_types
.0
.get(&metadata::CompositeTypeName(type_name.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ::ref_cast here, perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@soupi soupi added this pull request to the merge queue Jul 10, 2024
Merged via the queue into main with commit 3941422 Jul 10, 2024
31 checks passed
@soupi soupi deleted the gil/config-v5-with-native-operations-rename branch July 10, 2024 08:39
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.

2 participants