Skip to content

Commit effd73c

Browse files
author
Gil Mizrahi
authored
Warn when the configuration is deprecated (#537)
### What We'd like to mark configuration version 3 and 4 as deprecated. We'll mention this in the docs, and also trace a warning when starting the connector with an older configuration version. ``` {"timestamp":"2024-07-16T13:02:04.857565Z","level":"WARN","fields":{"message":"Warning: ndc-postgres configuration version '3' is deprecated.\nConsider upgrading to the latest version:\nhttps://hasura.io/docs/3.0/connectors/postgresql/configuration-reference/#upgrading-the-configuration-format-version"},"target":"ndc_postgres::connector"} ``` ### How trace a warning pointing at how to upgrade the configuration.
1 parent 0ec6f62 commit effd73c

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
- Support ndc-sdk-rs v0.2.1, including changes to error messages.
1313
[#520](https://github.com/hasura/ndc-postgres/pull/520)
14+
- Warn when starting the connector with an older configuration version.
15+
[#537](https://github.com/hasura/ndc-postgres/pull/537)
1416

1517
### Fixed
1618

crates/configuration/src/configuration.rs

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ impl ParsedConfiguration {
4747
pub fn initial() -> Self {
4848
ParsedConfiguration::Version5(version5::ParsedConfiguration::empty())
4949
}
50+
pub fn version(&self) -> VersionTag {
51+
match self {
52+
ParsedConfiguration::Version3(_) => VersionTag::Version3,
53+
ParsedConfiguration::Version4(_) => VersionTag::Version4,
54+
ParsedConfiguration::Version5(_) => VersionTag::Version5,
55+
}
56+
}
5057
}
5158

5259
/// The 'Configuration' type collects all the information necessary to serve queries at runtime.

crates/configuration/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ pub enum VersionTag {
2525
Version5,
2626
}
2727

28+
/// Emit deprecation warning text if the version is deprecated.
29+
pub fn deprecated_config_warning(version: VersionTag) -> Option<String> {
30+
match version {
31+
VersionTag::Version3 => Some(
32+
"Warning: ndc-postgres configuration version '3' is deprecated.
33+
Consider upgrading to the latest version:
34+
https://hasura.io/docs/3.0/connectors/postgresql/configuration-reference/#upgrading-the-configuration-format-version".to_string()
35+
),
36+
VersionTag::Version4 => Some(
37+
"Warning: ndc-postgres configuration version '4' is deprecated.
38+
Consider upgrading to the latest version:
39+
https://hasura.io/docs/3.0/connectors/postgresql/configuration-reference/#upgrading-the-configuration-format-version".to_string()
40+
),
41+
VersionTag::Version5 => None,
42+
}
43+
}
44+
2845
#[cfg(test)]
2946
pub mod common {
3047
use std::fmt::Write;

crates/connectors/ndc-postgres/src/connector.rs

+7
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for PostgresSetup<Env> {
256256
}
257257
})?;
258258

259+
// Warn if the configuration version is deprecated.
260+
if let Some(warning) =
261+
configuration::deprecated_config_warning(parsed_configuration.version())
262+
{
263+
tracing::warn!("{}", warning);
264+
}
265+
259266
let runtime_configuration =
260267
configuration::make_runtime_configuration(parsed_configuration, &self.environment)
261268
.map_err(|error| {

0 commit comments

Comments
 (0)