diff --git a/changelog.md b/changelog.md index 2b7110d7a..52e3689b0 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,8 @@ - Support ndc-sdk-rs v0.2.1, including changes to error messages. [#520](https://github.com/hasura/ndc-postgres/pull/520) +- Warn when starting the connector with an older configuration version. + [#537](https://github.com/hasura/ndc-postgres/pull/537) ### Fixed diff --git a/crates/configuration/src/configuration.rs b/crates/configuration/src/configuration.rs index f62e868ab..4f6cc35a6 100644 --- a/crates/configuration/src/configuration.rs +++ b/crates/configuration/src/configuration.rs @@ -47,6 +47,13 @@ impl ParsedConfiguration { pub fn initial() -> Self { ParsedConfiguration::Version5(version5::ParsedConfiguration::empty()) } + pub fn version(&self) -> VersionTag { + match self { + ParsedConfiguration::Version3(_) => VersionTag::Version3, + ParsedConfiguration::Version4(_) => VersionTag::Version4, + ParsedConfiguration::Version5(_) => VersionTag::Version5, + } + } } /// The 'Configuration' type collects all the information necessary to serve queries at runtime. diff --git a/crates/configuration/src/lib.rs b/crates/configuration/src/lib.rs index b2ec4f9ea..f836df1ba 100644 --- a/crates/configuration/src/lib.rs +++ b/crates/configuration/src/lib.rs @@ -25,6 +25,23 @@ pub enum VersionTag { Version5, } +/// Emit deprecation warning text if the version is deprecated. +pub fn deprecated_config_warning(version: VersionTag) -> Option { + match version { + VersionTag::Version3 => Some( + "Warning: ndc-postgres configuration version '3' is deprecated. +Consider upgrading to the latest version: +https://hasura.io/docs/3.0/connectors/postgresql/configuration-reference/#upgrading-the-configuration-format-version".to_string() + ), + VersionTag::Version4 => Some( + "Warning: ndc-postgres configuration version '4' is deprecated. +Consider upgrading to the latest version: +https://hasura.io/docs/3.0/connectors/postgresql/configuration-reference/#upgrading-the-configuration-format-version".to_string() + ), + VersionTag::Version5 => None, + } +} + #[cfg(test)] pub mod common { use std::fmt::Write; diff --git a/crates/connectors/ndc-postgres/src/connector.rs b/crates/connectors/ndc-postgres/src/connector.rs index 0480156ff..2684635a8 100644 --- a/crates/connectors/ndc-postgres/src/connector.rs +++ b/crates/connectors/ndc-postgres/src/connector.rs @@ -256,6 +256,13 @@ impl ConnectorSetup for PostgresSetup { } })?; + // Warn if the configuration version is deprecated. + if let Some(warning) = + configuration::deprecated_config_warning(parsed_configuration.version()) + { + tracing::warn!("{}", warning); + } + let runtime_configuration = configuration::make_runtime_configuration(parsed_configuration, &self.environment) .map_err(|error| {