From f74a000506ff7a94ef4b0f1d931e12673e8ab4a7 Mon Sep 17 00:00:00 2001 From: jkomyno Date: Thu, 31 Oct 2024 18:35:21 +0400 Subject: [PATCH] fix(psl): don't trust datasource array to contain at least 1 datasource --- psl/psl-core/src/lib.rs | 9 +++++++-- psl/psl-core/src/validate/generator_loader.rs | 8 +++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/psl/psl-core/src/lib.rs b/psl/psl-core/src/lib.rs index 87013ed0dd1..04993c44634 100644 --- a/psl/psl-core/src/lib.rs +++ b/psl/psl-core/src/lib.rs @@ -176,8 +176,13 @@ 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 active_provider = datasources[0].active_provider; - let generators = generator_loader::load_generators_from_ast(schema_ast, diagnostics, active_provider); + let feature_map_with_provider = datasources + .get(0) + .map(|ds| ds.active_provider) + .map(FeatureMapWithProvider::new) + .unwrap_or_else(|| ALL_PREVIEW_FEATURES); + + let generators = generator_loader::load_generators_from_ast(schema_ast, diagnostics, &feature_map_with_provider); Configuration::new(generators, datasources, diagnostics.warnings().to_owned()) } diff --git a/psl/psl-core/src/validate/generator_loader.rs b/psl/psl-core/src/validate/generator_loader.rs index 4cc1891a056..142f593beba 100644 --- a/psl/psl-core/src/validate/generator_loader.rs +++ b/psl/psl-core/src/validate/generator_loader.rs @@ -25,12 +25,12 @@ 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, - connector_provider: &str, + feature_map_with_provider: &FeatureMapWithProvider<'_>, ) -> Vec { let mut generators: Vec = Vec::new(); for gen in ast_schema.generators() { - if let Some(generator) = lift_generator(gen, diagnostics, connector_provider) { + if let Some(generator) = lift_generator(gen, diagnostics, feature_map_with_provider) { generators.push(generator); } } @@ -41,7 +41,7 @@ pub(crate) fn load_generators_from_ast( fn lift_generator<'a>( ast_generator: &ast::GeneratorConfig, diagnostics: &mut Diagnostics, - connector_provider: &'a str, + feature_map_with_provider: &FeatureMapWithProvider<'_>, ) -> Option { let generator_name = ast_generator.name.name.as_str(); let args: HashMap<_, &Expression> = ast_generator @@ -97,8 +97,6 @@ fn lift_generator<'a>( .and_then(|arg| coerce_array(arg, &StringFromEnvVar::coerce, diagnostics)) .unwrap_or_default(); - let feature_map_with_provider = FeatureMapWithProvider::<'a>::new(connector_provider); - // for compatibility reasons we still accept the old experimental key let preview_features = args .get(PREVIEW_FEATURES_KEY)