Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qe: sync @default(now()) and @updatedAt within a request
There are two points of difficulty here: - Using the same PrismaValue::DateTime as the value of `now()` and `@updatedAt` for the duration of a request. We achieve that through a task local. Alternatives: passing the context through explicitly. I tried, it's a massive refactoring. - The loss of precision due to the `From<PrismaValue>` impl for `QueryValue`. This is fixed by adding a `QueryValue::DateTime` variant that preserves the original precision.
- Loading branch information
Showing
17 changed files
with
185 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_12572.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schema))] | ||
mod prisma_12572 { | ||
fn schema() -> String { | ||
r#" | ||
model Test1 { | ||
#id(id, String, @id) | ||
up1 DateTime @updatedAt | ||
cr1 DateTime @default(now()) | ||
cr2 DateTime @default(now()) | ||
up2 DateTime @updatedAt | ||
test2s Test2[] | ||
} | ||
model Test2 { | ||
#id(id, String, @id) | ||
test1Id String @unique | ||
test1 Test1 @relation(fields: [test1Id], references: [id]) | ||
cr DateTime @default(now()) | ||
up DateTime @updatedAt | ||
} | ||
"# | ||
.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn all_generated_timestamps_are_the_same(runner: Runner) -> TestResult<()> { | ||
runner | ||
.query(r#"mutation { createOneTest1(data: {id:"one", test2s: { create: {id: "two"}}}) { id }}"#) | ||
.await? | ||
.assert_success(); | ||
let testones = runner.query(r#"{ findManyTest1 { id up1 cr1 cr2 up2 } }"#).await?; | ||
let testtwos = runner.query(r#"{ findManyTest2 { id up cr } }"#).await?; | ||
testones.assert_success(); | ||
testtwos.assert_success(); | ||
|
||
let testones_json = testones.to_json_value(); | ||
let testtwos_json = testtwos.to_json_value(); | ||
let testone_obj = &testones_json["data"]["findManyTest1"][0]; | ||
let testtwo_obj = &testtwos_json["data"]["findManyTest2"][0]; | ||
|
||
let values = &[ | ||
&testone_obj["up1"].as_str().unwrap(), | ||
&testone_obj["up2"].as_str().unwrap(), | ||
&testone_obj["cr1"].as_str().unwrap(), | ||
&testone_obj["cr2"].as_str().unwrap(), | ||
&testtwo_obj["up"].as_str().unwrap(), | ||
&testtwo_obj["cr"].as_str().unwrap(), | ||
]; | ||
|
||
// assert that all the datetimes are the same | ||
for datetimes in values.windows(2) { | ||
assert_eq!(datetimes[0], datetimes[1]); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.