diff --git a/libs/dml/src/model.rs b/libs/dml/src/model.rs index b441756b20ea..392485b55f3b 100644 --- a/libs/dml/src/model.rs +++ b/libs/dml/src/model.rs @@ -244,7 +244,7 @@ impl OperatorClass { } } -///A field in an index that optionally defines a sort order and length limit. +/// A field in an index that optionally defines a sort order and length limit. #[derive(Debug, PartialEq, Clone)] pub struct IndexField { pub path: Vec<(String, Option)>, @@ -291,7 +291,7 @@ pub struct PrimaryKeyDefinition { pub clustered: Option, } -///A field in a Primary Key that optionally defines a sort order and length limit. +/// A field in a Primary Key that optionally defines a sort order and length limit. #[derive(Debug, PartialEq, Clone)] pub struct PrimaryKeyField { pub name: String, @@ -325,15 +325,15 @@ impl AsRef for SortOrder { } } -/// A unique criteria is a set of fields through which a record can be uniquely identified. +/// A unique criterion is a set of fields through which a record can be uniquely identified. #[derive(Debug)] -pub struct UniqueCriteria<'a> { +pub struct UniqueCriterion<'a> { pub fields: Vec<&'a ScalarField>, } -impl<'a> UniqueCriteria<'a> { - pub fn new(fields: Vec<&'a ScalarField>) -> UniqueCriteria<'a> { - UniqueCriteria { fields } +impl<'a> UniqueCriterion<'a> { + pub fn new(fields: Vec<&'a ScalarField>) -> UniqueCriterion<'a> { + UniqueCriterion { fields } } } @@ -452,20 +452,22 @@ impl Model { } } - /// optional unique fields are NOT considered a unique criteria - /// used for: A Model must have at least one STRICT unique criteria. - pub fn strict_unique_criterias(&self) -> Vec { + /// Optional unique fields are NOT considered a unique criterion. + /// + /// Used for: A Model must have at least one STRICT unique criteria. + pub fn strict_unique_criterias(&self) -> Vec { self.unique_criterias(false) } - /// optional unique fields are considered a unique criteria - /// used for: A relation must reference one LOOSE unique criteria. (optional fields are okay in this case) - pub fn loose_unique_criterias(&self) -> Vec { + /// Optional unique fields are considered a unique criterion + /// + /// Used for: A relation must reference one LOOSE unique criteria. (optional fields are okay in this case) + pub fn loose_unique_criterias(&self) -> Vec { self.unique_criterias(true) } - /// returns the order of unique criterias ordered based on their precedence - fn unique_criterias(&self, allow_optional: bool) -> Vec { + /// Returns the order of unique criterias ordered based on their precedence + fn unique_criterias(&self, allow_optional: bool) -> Vec { let mut result = Vec::new(); // first candidate: primary key @@ -500,14 +502,14 @@ impl Model { .iter() .any(|f| f.is_commented_out || (f.is_optional() && !allow_optional)) { - result.push(UniqueCriteria::new(id_fields)); + result.push(UniqueCriterion::new(id_fields)); } } } // second candidate: any unique constraint where all fields are required { - let mut unique_field_combi: Vec = self + let mut unique_field_combi: Vec = self .indices .iter() .filter(|id| id.is_unique()) @@ -523,7 +525,7 @@ impl Model { let no_fields_are_ineligible = !fields.iter().any(|f| f.is_commented_out); let all_fields_are_required = fields.iter().all(|f| f.is_required()); ((all_fields_are_required || allow_optional) && no_fields_are_ineligible) - .then(|| UniqueCriteria::new(fields)) + .then(|| UniqueCriterion::new(fields)) }) .collect(); diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/models.rs b/psl/psl-core/src/validate/validation_pipeline/validations/models.rs index cd175989cbb7..af2516f9f9a4 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/models.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/models.rs @@ -10,7 +10,7 @@ use crate::{ use parser_database::walkers::{ModelWalker, PrimaryKeyWalker}; use std::{borrow::Cow, collections::HashMap}; -/// A model must have either a primary key, or a unique criteria +/// A model must have either a primary key, or a unique criterion /// with no optional, commented-out or unsupported fields. pub(super) fn has_a_strict_unique_criteria(model: ModelWalker<'_>, ctx: &mut Context<'_>) { if model.is_ignored() { diff --git a/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs b/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs index 0c3ce9d08e3d..7f63bef1e2c1 100644 --- a/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs +++ b/psl/psl-core/src/validate/validation_pipeline/validations/relations.rs @@ -146,9 +146,9 @@ pub(super) fn references_unique_fields(relation: InlineRelationWalker<'_>, ctx: let model = relation.referenced_model().name(); let message = if fields.len() == 1 { - format!("The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `{}` in the model `{}`.", fields.join(", "), model) + format!("The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `{}` in the model `{}`.", fields.join(", "), model) } else { - format!("The argument `references` must refer to a unique criteria in the related model. Consider adding an `@@unique([{}])` attribute to the model `{}`.", fields.join(", "), model) + format!("The argument `references` must refer to a unique criterion in the related model. Consider adding an `@@unique([{}])` attribute to the model `{}`.", fields.join(", "), model) }; ctx.push_error(DatamodelError::new_attribute_validation_error( @@ -200,7 +200,7 @@ fn referencing_fields_in_correct_order(relation: InlineRelationWalker<'_>, ctx: ctx.push_error(DatamodelError::new_validation_error( &format!( - "The argument `references` must refer to a unique criteria in the related model `{}` using the same order of fields. Please check the ordering in the following fields: `{}`.", + "The argument `references` must refer to a unique criterion in the related model `{}` using the same order of fields. Please check the ordering in the following fields: `{}`.", relation.referenced_model().name(), relation.referenced_fields().map(|f| f.name()).join(", ") ), diff --git a/psl/psl/tests/attributes/relations/relations_negative.rs b/psl/psl/tests/attributes/relations/relations_negative.rs index fdd862d6169c..0acb30f83723 100644 --- a/psl/psl/tests/attributes/relations/relations_negative.rs +++ b/psl/psl/tests/attributes/relations/relations_negative.rs @@ -1029,7 +1029,7 @@ fn should_fail_if_not_using_unique_constraint_with_single_one_to_many() { "#}; let expect = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `custom_id` in the model `A`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `custom_id` in the model `A`. --> schema.prisma:22  |  21 |  a_id String @@ -1087,14 +1087,14 @@ fn multiple_relation_validation_errors_do_not_prevent_each_other_across_models() "#; let expected_error = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `USER_NON_UNIQUE_ID` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `USER_NON_UNIQUE_ID` in the model `User`. --> schema.prisma:15  |  14 |  USER_NON_UNIQUE_ID Int @db.UnsignedInt 15 |  User User @relation(fields: [USER_NON_UNIQUE_ID], references: [USER_NON_UNIQUE_ID], onUpdate: Restrict, map: "FK_USER_NON_UNIQUE_ID") 16 |   |  - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `STOCK_NON_UNIQUE_ID` in the model `stock`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `STOCK_NON_UNIQUE_ID` in the model `stock`. --> schema.prisma:38  |  37 |  STOCK_ID Int @id @db.UnsignedInt diff --git a/psl/psl/tests/attributes/relations/relations_new.rs b/psl/psl/tests/attributes/relations/relations_new.rs index 767bf6dbe2e1..016bca0395cc 100644 --- a/psl/psl/tests/attributes/relations/relations_new.rs +++ b/psl/psl/tests/attributes/relations/relations_new.rs @@ -326,7 +326,7 @@ fn relation_must_error_when_referenced_fields_are_not_a_unique_criteria() { "#; let expect = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `firstName` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `firstName` in the model `User`. --> schema.prisma:12  |  11 |  userName String @@ -358,7 +358,7 @@ fn relation_must_error_when_referenced_compound_fields_are_not_a_unique_criteria "#}; let expect = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@@unique([firstName, lastName])` attribute to the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@@unique([firstName, lastName])` attribute to the model `User`. --> schema.prisma:13  |  12 |  lastName String @@ -412,7 +412,7 @@ fn relation_must_error_when_referenced_fields_are_multiple_uniques() { "#; let expect = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@@unique([id, firstName])` attribute to the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@@unique([id, firstName])` attribute to the model `User`. --> schema.prisma:14  |  13 |  // the relation is referencing two uniques. That is too much. diff --git a/psl/psl/tests/capabilities/cockroachdb.rs b/psl/psl/tests/capabilities/cockroachdb.rs index 6e7b25efd9d2..c2839e65b0da 100644 --- a/psl/psl/tests/capabilities/cockroachdb.rs +++ b/psl/psl/tests/capabilities/cockroachdb.rs @@ -81,7 +81,7 @@ fn non_unique_relation_criteria_support() { let error = parse_unwrap_err(dml); let expectation = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. --> schema.prisma:9  |   8 |  assigneeName String diff --git a/psl/psl/tests/capabilities/postgres.rs b/psl/psl/tests/capabilities/postgres.rs index 884582d5d37b..461b39a93ab0 100644 --- a/psl/psl/tests/capabilities/postgres.rs +++ b/psl/psl/tests/capabilities/postgres.rs @@ -123,7 +123,7 @@ fn non_unique_relation_criteria_support() { let error = parse_unwrap_err(dml); let expectation = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. --> schema.prisma:9  |   8 |  assigneeName String diff --git a/psl/psl/tests/capabilities/sqlite.rs b/psl/psl/tests/capabilities/sqlite.rs index ee02886eb2b8..7e30d3441d17 100644 --- a/psl/psl/tests/capabilities/sqlite.rs +++ b/psl/psl/tests/capabilities/sqlite.rs @@ -161,7 +161,7 @@ fn non_unique_relation_criteria_support() { let error = parse_unwrap_err(dml); let expectation = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. --> schema.prisma:9  |   8 |  assigneeName String diff --git a/psl/psl/tests/capabilities/sqlserver.rs b/psl/psl/tests/capabilities/sqlserver.rs index 26b88b05d8ed..9cf748666187 100644 --- a/psl/psl/tests/capabilities/sqlserver.rs +++ b/psl/psl/tests/capabilities/sqlserver.rs @@ -145,7 +145,7 @@ fn non_unique_relation_criteria_support() { let error = parse_unwrap_err(dml); let expectation = expect![[r#" - error: Error parsing attribute "@relation": The argument `references` must refer to a unique criteria in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. + error: Error parsing attribute "@relation": The argument `references` must refer to a unique criterion in the related model. Consider adding an `@unique` attribute to the field `name` in the model `User`. --> schema.prisma:9  |   8 |  assigneeName String @@ -202,7 +202,7 @@ fn key_order_enforcement_support() { let error = parse_unwrap_err(dml); let expectation = expect![[r#" - error: Error validating: The argument `references` must refer to a unique criteria in the related model `Todo` using the same order of fields. Please check the ordering in the following fields: `id2, id1`. + error: Error validating: The argument `references` must refer to a unique criterion in the related model `Todo` using the same order of fields. Please check the ordering in the following fields: `id2, id1`. --> schema.prisma:19  |  18 |