From 6328f2e8f8b0e18a79ae14993587ca34acac3be1 Mon Sep 17 00:00:00 2001 From: jkomyno Date: Tue, 26 Nov 2024 20:54:08 +0100 Subject: [PATCH] fix(connector-test-kit-rs): fix tests by enabling support for "FeatureMapWithProvider" --- psl/diagnostics/src/warning.rs | 2 +- psl/psl-core/src/common/preview_features.rs | 27 ++++++++++--------- psl/psl-core/src/lib.rs | 2 +- psl/psl-core/src/validate/generator_loader.rs | 6 ++--- psl/psl/src/lib.rs | 1 + .../src/connector_tag/postgres.rs | 2 +- .../src/datamodel_rendering/mod.rs | 11 ++++---- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/psl/diagnostics/src/warning.rs b/psl/diagnostics/src/warning.rs index fa5dfad0d4bf..ed9cb5e36ee0 100644 --- a/psl/diagnostics/src/warning.rs +++ b/psl/diagnostics/src/warning.rs @@ -41,7 +41,7 @@ impl DatamodelWarning { } pub fn new_preview_feature_renamed_for_provider( - provider: &'static str, + provider: &str, deprecated_feature: &str, renamed_feature: impl Display, prisly_link_endpoint: &str, diff --git a/psl/psl-core/src/common/preview_features.rs b/psl/psl-core/src/common/preview_features.rs index d0f9bfa033cd..492e7705139f 100644 --- a/psl/psl-core/src/common/preview_features.rs +++ b/psl/psl-core/src/common/preview_features.rs @@ -89,12 +89,12 @@ features!( ); #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] -struct RenamedFeatureKey { +struct RenamedFeatureKey<'a> { /// The old, deprecated preview feature that was renamed. pub from: PreviewFeature, /// The provider that the feature was renamed for. - pub provider: Option<&'static str>, + pub provider: Option<&'a str>, } #[derive(Debug, Copy, Clone)] @@ -107,9 +107,9 @@ pub(crate) struct RenamedFeatureValue { } #[derive(Debug, Clone)] -pub(crate) enum RenamedFeature { +pub(crate) enum RenamedFeature<'a> { /// The preview feature was renamed for a specific provider. - ForProvider((&'static str, RenamedFeatureValue)), + ForProvider((&'a str, RenamedFeatureValue)), /// The preview feature was renamed for all providers. AllProviders(RenamedFeatureValue), @@ -127,7 +127,7 @@ struct FeatureMap { deprecated: PreviewFeatures, /// History of renamed deprecated features. - renamed: BTreeMap, + renamed: BTreeMap, RenamedFeatureValue>, /// Hidden preview features are valid features, but are not propagated into the tooling /// (as autocomplete or similar) or into error messages (eg. showing a list of valid features). @@ -135,18 +135,19 @@ struct FeatureMap { } #[derive(Debug, Clone)] -pub struct FeatureMapWithProvider { - provider: Option<&'static str>, +pub struct FeatureMapWithProvider<'a> { + provider: Option<&'a str>, feature_map: FeatureMap, } /// The default feature map with an unknown provider. /// This is used for convenience in `prisma/language-tools`, which needs the list of all available preview features /// before a provider is necessarily known. -pub static ALL_PREVIEW_FEATURES: LazyLock = LazyLock::new(|| FeatureMapWithProvider::new(None)); +pub static ALL_PREVIEW_FEATURES: LazyLock> = + LazyLock::new(|| FeatureMapWithProvider::new(None)); -impl FeatureMapWithProvider { - pub fn new(connector_provider: Option<&'static str>) -> FeatureMapWithProvider { +impl<'a> FeatureMapWithProvider<'a> { + pub fn new(connector_provider: Option<&'a str>) -> FeatureMapWithProvider<'a> { // Generator preview features (alphabetically sorted) let feature_map: FeatureMap = FeatureMap { active: enumflags2::make_bitflags!(PreviewFeature::{ @@ -252,12 +253,12 @@ impl FeatureMapWithProvider { } /// Was the given preview feature deprecated and renamed? - pub(crate) fn is_renamed(&self, flag: PreviewFeature) -> Option { + pub(crate) fn is_renamed(&'a self, flag: PreviewFeature) -> Option> { // Check for a renamed feature specific to the provider. This is only possible if a provider is not None. let provider_specific = self.provider.and_then(|provider| { self.feature_map .renamed - .get(&RenamedFeatureKey { + .get(&RenamedFeatureKey::<'a> { from: flag, provider: Some(provider), }) @@ -268,7 +269,7 @@ impl FeatureMapWithProvider { provider_specific.or_else(|| { self.feature_map .renamed - .get(&RenamedFeatureKey { + .get(&RenamedFeatureKey::<'a> { from: flag, provider: None, }) diff --git a/psl/psl-core/src/lib.rs b/psl/psl-core/src/lib.rs index 9cef8bbac793..8896c5dba83f 100644 --- a/psl/psl-core/src/lib.rs +++ b/psl/psl-core/src/lib.rs @@ -176,7 +176,7 @@ fn validate_configuration( // We need to know the active provider to determine which features are active. // This was originally introduced because the `fullTextSearch` preview feature will hit GA stage // one connector at a time (Prisma 6 GAs it for MySQL, other connectors may follow in future releases). - let feature_map_with_provider: FeatureMapWithProvider = datasources + let feature_map_with_provider: FeatureMapWithProvider<'_> = datasources .first() .map(|ds| Some(ds.active_provider)) .map(FeatureMapWithProvider::new) diff --git a/psl/psl-core/src/validate/generator_loader.rs b/psl/psl-core/src/validate/generator_loader.rs index cb62d36d4bb6..d64c537b05b3 100644 --- a/psl/psl-core/src/validate/generator_loader.rs +++ b/psl/psl-core/src/validate/generator_loader.rs @@ -25,7 +25,7 @@ const FIRST_CLASS_PROPERTIES: &[&str] = &[PROVIDER_KEY, OUTPUT_KEY, BINARY_TARGE pub(crate) fn load_generators_from_ast( ast_schema: &ast::SchemaAst, diagnostics: &mut Diagnostics, - feature_map_with_provider: &FeatureMapWithProvider, + feature_map_with_provider: &FeatureMapWithProvider<'_>, ) -> Vec { let mut generators: Vec = Vec::new(); @@ -41,7 +41,7 @@ pub(crate) fn load_generators_from_ast( fn lift_generator( ast_generator: &ast::GeneratorConfig, diagnostics: &mut Diagnostics, - feature_map_with_provider: &FeatureMapWithProvider, + feature_map_with_provider: &FeatureMapWithProvider<'_>, ) -> Option { let generator_name = ast_generator.name.name.as_str(); let args: HashMap<_, &Expression> = ast_generator @@ -140,7 +140,7 @@ fn lift_generator( fn parse_and_validate_preview_features( preview_features: Vec<&str>, - feature_map_with_provider: &FeatureMapWithProvider, + feature_map_with_provider: &FeatureMapWithProvider<'_>, span: ast::Span, diagnostics: &mut Diagnostics, ) -> BitFlags { diff --git a/psl/psl/src/lib.rs b/psl/psl/src/lib.rs index b58b84d95546..32bc611e9a21 100644 --- a/psl/psl/src/lib.rs +++ b/psl/psl/src/lib.rs @@ -22,6 +22,7 @@ pub use psl_core::{ ConnectorRegistry, Datasource, DatasourceConnectorData, + FeatureMapWithProvider, Generator, GeneratorConfigValue, PreviewFeature, diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/postgres.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/postgres.rs index 38318358604f..0a8fe5004443 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/postgres.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/postgres.rs @@ -16,7 +16,7 @@ impl ConnectorTagInterface for PostgresConnectorTag { } fn datamodel_provider(&self) -> &'static str { - "postgres" + "postgresql" } fn datamodel_renderer(&self) -> Box { diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/datamodel_rendering/mod.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/datamodel_rendering/mod.rs index 6e2ba4b2c7b3..8af9b6075546 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/datamodel_rendering/mod.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/datamodel_rendering/mod.rs @@ -12,7 +12,7 @@ use crate::{ use indoc::indoc; use itertools::Itertools; use once_cell::sync::Lazy; -use psl::ALL_PREVIEW_FEATURES; +use psl::FeatureMapWithProvider; use regex::Regex; /// Test configuration, loaded once at runtime. @@ -42,7 +42,7 @@ pub fn render_test_datamodel( isolation_level: Option<&'static str>, ) -> String { let (tag, version) = CONFIG.test_connector().unwrap(); - let preview_features = render_preview_features(excluded_features); + let preview_features = render_preview_features(tag.datamodel_provider(), excluded_features); let is_multi_schema = !db_schemas.is_empty(); @@ -93,13 +93,14 @@ fn process_template(template: String, renderer: Box) -> S }) } -fn render_preview_features(excluded_features: &[&str]) -> String { +fn render_preview_features(provider: &str, excluded_features: &[&str]) -> String { let excluded_features: Vec<_> = excluded_features.iter().map(|f| format!(r#""{f}""#)).collect(); + let feature_map_with_provider = FeatureMapWithProvider::new(Some(provider)); - ALL_PREVIEW_FEATURES + feature_map_with_provider .active_features() .iter() - .chain(ALL_PREVIEW_FEATURES.hidden_features()) + .chain(feature_map_with_provider.hidden_features()) .map(|f| format!(r#""{f}""#)) .filter(|f| !excluded_features.contains(f)) .join(", ")