-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
…tive-operations-rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from v4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from v4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from v4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy paste from v4.
pub types: Types, | ||
#[serde(default)] | ||
pub native_operations: NativeOperations, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these two are different.
There was a problem hiding this comment.
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.
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), | ||
} | ||
} |
There was a problem hiding this comment.
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.
pub fn lookup_native_query( | ||
pub fn lookup_native_mutation( | ||
&self, | ||
procedure_name: &str, | ||
) -> Result<&metadata::NativeQueryInfo, Error> { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
"types": { | ||
"scalar": {}, | ||
"composite": {} | ||
}, | ||
"nativeOperations": { | ||
"queries": {}, | ||
"mutations": {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change.
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)), | ||
]), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
crates/cli/src/native_operations.rs
Outdated
} { | ||
entry.insert(new_native_operation); | ||
} else { | ||
anyhow::bail!("A Native Operation with the name '{}' already exists. To override, use the --override flag.", name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
// 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 | ||
)] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
// 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)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, here.
There was a problem hiding this comment.
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())) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
What
We introduce ndc-postgres configuration version "v5".
This version changes two things:
Renames the field
nativeQueries
tonativeOperations
, 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:We nest
scalarTypes
andcompositeTypes
under one field,types
:How
Might be useful to read as commits.
We first copy paste v4 to v5, then create types for
Types
andNativeOperations
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.