Skip to content

Commit

Permalink
Merge branch 'main' into feat/orm-399-limit-updatemany
Browse files Browse the repository at this point in the history
  • Loading branch information
FGoessler committed Jan 13, 2025
2 parents d8523a0 + a046f87 commit 4107472
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
3 changes: 3 additions & 0 deletions query-engine/dmmf/src/ast_builders/datamodel_ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ fn composite_type_field_to_dmmf(field: walkers::CompositeTypeFieldWalker<'_>) ->
relation_from_fields: None,
relation_to_fields: None,
relation_on_delete: None,
relation_on_update: None,
field_type: match field.r#type() {
ScalarFieldType::CompositeType(ct) => field.walk(ct).name().to_owned(),
ScalarFieldType::Enum(enm) => field.walk(enm).name().to_owned(),
Expand Down Expand Up @@ -210,6 +211,7 @@ fn scalar_field_to_dmmf(field: walkers::ScalarFieldWalker<'_>) -> Field {
relation_from_fields: None,
relation_to_fields: None,
relation_on_delete: None,
relation_on_update: None,
is_generated: Some(false),
is_updated_at: Some(field.is_updated_at()),
documentation: ast_field.documentation().map(ToOwned::to_owned),
Expand Down Expand Up @@ -245,6 +247,7 @@ fn relation_field_to_dmmf(field: walkers::RelationFieldWalker<'_>) -> Field {
.unwrap_or_default(),
),
relation_on_delete: field.explicit_on_delete().map(|od| od.to_string()),
relation_on_update: field.explicit_on_update().map(|ou| ou.to_string()),
is_generated: Some(false),
is_updated_at: Some(false),
documentation: ast_field.documentation().map(ToOwned::to_owned),
Expand Down
3 changes: 3 additions & 0 deletions query-engine/dmmf/src/serialization_ast/datamodel_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ pub struct Field {
#[serde(skip_serializing_if = "Option::is_none")]
pub relation_on_delete: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub relation_on_update: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub is_generated: Option<bool>,

Expand Down
Binary file not shown.
30 changes: 22 additions & 8 deletions query-engine/dmmf/test_files/functions.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
"nativeType": null,
"default": {
"name": "cuid",
"args": [1]
"args": [
1
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand All @@ -87,7 +89,9 @@
"nativeType": null,
"default": {
"name": "cuid",
"args": [1]
"args": [
1
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand All @@ -105,7 +109,9 @@
"nativeType": null,
"default": {
"name": "cuid",
"args": [2]
"args": [
2
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand All @@ -123,7 +129,9 @@
"nativeType": null,
"default": {
"name": "uuid",
"args": [4]
"args": [
4
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand All @@ -141,7 +149,9 @@
"nativeType": null,
"default": {
"name": "uuid",
"args": [4]
"args": [
4
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand All @@ -159,7 +169,9 @@
"nativeType": null,
"default": {
"name": "uuid",
"args": [7]
"args": [
7
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand Down Expand Up @@ -195,7 +207,9 @@
"nativeType": null,
"default": {
"name": "nanoid",
"args": [6]
"args": [
6
]
},
"isGenerated": false,
"isUpdatedAt": false
Expand Down Expand Up @@ -310,4 +324,4 @@
]
}
]
}
}
1 change: 1 addition & 0 deletions schema-engine/datamodel-renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
once_cell = "1.15.0"
psl.workspace = true
regex.workspace = true
itertools.workspace = true
base64 = "0.13.1"

[dev-dependencies]
Expand Down
31 changes: 28 additions & 3 deletions schema-engine/datamodel-renderer/src/configuration/generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::value::{Array, Documentation, Env, Text, Value};
use itertools::Itertools;
use psl::PreviewFeature;
use std::{borrow::Cow, fmt};

Expand Down Expand Up @@ -143,7 +144,7 @@ impl fmt::Display for Generator<'_> {
writeln!(f, "binaryTargets = {}", self.binary_targets)?;
}

for (k, v) in self.config.iter() {
for (k, v) in self.config.iter().sorted_by_key(|(k, _)| k) {
writeln!(f, "{k} = {v}")?;
}

Expand Down Expand Up @@ -198,14 +199,38 @@ mod tests {
output = "/dev/null"
previewFeatures = ["multiSchema", "postgresqlExtensions"]
binaryTargets = [env("BINARY TARGET")]
afterGenerate = ["lambda", [], ["print", ["quote", "done!"]]]
customFeatures = ["enums", "models"]
customValue = "meow"
otherValue = "purr"
customFeatures = ["enums", "models"]
afterGenerate = ["lambda", [], ["print", ["quote", "done!"]]]
}
"#]];

let rendered = psl::reformat(&format!("{generator}"), 2).unwrap();
expected.assert_eq(&rendered)
}

#[test]
fn creates_consistent_ordering() {
let mut generator1 = Generator::new("client", Env::value("prisma-client-js"));
generator1.push_config_value("first", "A");
generator1.push_config_value("second", "B");
let rendered1 = psl::reformat(&format!("{generator1}"), 2).unwrap();

let mut generator2 = Generator::new("client", Env::value("prisma-client-js"));
generator2.push_config_value("second", "B");
generator2.push_config_value("first", "A");
let rendered2 = psl::reformat(&format!("{generator2}"), 2).unwrap();

let expected = expect![[r#"
generator client {
provider = "prisma-client-js"
first = "A"
second = "B"
}
"#]];

expected.assert_eq(&rendered1);
expected.assert_eq(&rendered2)
}
}

0 comments on commit 4107472

Please sign in to comment.