Skip to content

Warn when the configuration is deprecated #537

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 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions crates/configuration/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions crates/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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;
Expand Down
7 changes: 7 additions & 0 deletions crates/connectors/ndc-postgres/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ impl<Env: Environment + Send + Sync> ConnectorSetup for PostgresSetup<Env> {
}
})?;

// 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| {
Expand Down