From 893c63a749624bc1acf496c56596ae7491be2ccc Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Wed, 7 Feb 2024 13:59:57 +0100 Subject: [PATCH] fix(driver-adapters): fix `Bytes` issues for PlanetScale (#4695) * feat: bump @planetscale/database to 1.15.0 * test(driver-adapters): fix https://github.com/prisma/team-orm/issues/687, DRIVER_ADAPTERS_BRANCH=feat/update-planetscale * chore: fix typo, DRIVER_ADAPTERS_BRANCH=feat/update-planetscale * [skip ci] chore: fix indentation --- .../tests/queries/data_types/bytes.rs | 91 ++++++++++++++++++- .../queries/data_types/through_relation.rs | 9 +- .../driver-adapters/executor/package.json | 2 +- 3 files changed, 91 insertions(+), 11 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/bytes.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/bytes.rs index a4957d75e1ab..b1480451eb61 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/bytes.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/bytes.rs @@ -4,6 +4,87 @@ use query_engine_tests::*; mod bytes { use query_engine_tests::{run_query, EngineProtocol, Runner}; + #[test_suite] + mod issue_687 { + fn schema_common() -> String { + let schema = indoc! { + r#"model Parent { + #id(id, Int, @id) + + children Child[] + } + + model Child { + #id(childId, Int, @id) + + parentId Int? + parent Parent? @relation(fields: [parentId], references: [id]) + + bytes Bytes + } + "# + }; + + schema.to_owned() + } + + async fn create_common_children(runner: &Runner) -> TestResult<()> { + create_child( + &runner, + r#"{ + childId: 1, + bytes: "AQID", + }"#, + ) + .await?; + + create_child( + &runner, + r#"{ + childId: 2, + bytes: "FDSF" + }"#, + ) + .await?; + + create_parent( + &runner, + r#"{ id: 1, children: { connect: [{ childId: 1 }, { childId: 2 }] } }"#, + ) + .await?; + + Ok(()) + } + + #[connector_test(schema(schema_common))] + async fn common_types(runner: Runner) -> TestResult<()> { + create_common_children(&runner).await?; + + insta::assert_snapshot!( + run_query!(&runner, r#"{ findManyParent { id children { childId bytes } } }"#), + @r###"{"data":{"findManyParent":[{"id":1,"children":[{"childId":1,"bytes":"AQID"},{"childId":2,"bytes":"FDSF"}]}]}}"### + ); + + Ok(()) + } + + async fn create_child(runner: &Runner, data: &str) -> TestResult<()> { + runner + .query(format!("mutation {{ createOneChild(data: {}) {{ childId }} }}", data)) + .await? + .assert_success(); + Ok(()) + } + + async fn create_parent(runner: &Runner, data: &str) -> TestResult<()> { + runner + .query(format!("mutation {{ createOneParent(data: {}) {{ id }} }}", data)) + .await? + .assert_success(); + Ok(()) + } + } + #[connector_test] async fn read_one(runner: Runner) -> TestResult<()> { create_test_data(&runner).await?; @@ -14,7 +95,7 @@ mod bytes { insta::assert_snapshot!( res, - @r###"{"data":{"findUniqueTestModel":{"bytes":"AQID"}}}"### + @r###"{"data":{"findUniqueTestModel":{"bytes":"FSDF"}}}"### ); } EngineProtocol::Json => { @@ -37,7 +118,7 @@ mod bytes { insta::assert_snapshot!( res.to_string(), - @r###"{"data":{"findUniqueTestModel":{"bytes":{"$type":"Bytes","value":"AQID"}}}}"### + @r###"{"data":{"findUniqueTestModel":{"bytes":{"$type":"Bytes","value":"FSDF"}}}}"### ); } } @@ -55,7 +136,7 @@ mod bytes { insta::assert_snapshot!( res, - @r###"{"data":{"findManyTestModel":[{"bytes":"AQID"},{"bytes":"dGVzdA=="},{"bytes":null}]}}"### + @r###"{"data":{"findManyTestModel":[{"bytes":"FSDF"},{"bytes":"dGVzdA=="},{"bytes":null}]}}"### ); } query_engine_tests::EngineProtocol::Json => { @@ -75,7 +156,7 @@ mod bytes { insta::assert_snapshot!( res.to_string(), - @r###"{"data":{"findManyTestModel":[{"bytes":{"$type":"Bytes","value":"AQID"}},{"bytes":{"$type":"Bytes","value":"dGVzdA=="}},{"bytes":null}]}}"### + @r###"{"data":{"findManyTestModel":[{"bytes":{"$type":"Bytes","value":"FSDF"}},{"bytes":{"$type":"Bytes","value":"dGVzdA=="}},{"bytes":null}]}}"### ); } } @@ -84,7 +165,7 @@ mod bytes { } async fn create_test_data(runner: &Runner) -> TestResult<()> { - create_row(runner, r#"{ id: 1, bytes: "AQID" }"#).await?; + create_row(runner, r#"{ id: 1, bytes: "FSDF" }"#).await?; create_row(runner, r#"{ id: 2, bytes: "dGVzdA==" }"#).await?; create_row(runner, r#"{ id: 3 }"#).await?; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/through_relation.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/through_relation.rs index 08bb471881dd..192f2c46b064 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/through_relation.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/data_types/through_relation.rs @@ -31,13 +31,12 @@ mod scalar_relations { schema.to_owned() } - // TODO: fix https://github.com/prisma/team-orm/issues/684, https://github.com/prisma/team-orm/issues/687 and unexclude DAs + // TODO: fix https://github.com/prisma/team-orm/issues/684 and unexclude DAs. + // On Pg/Neon, this currently fails with "P2023": + // `Inconsistent column data: Unexpected conversion failure for field Child.bInt from Number(14324324234324.0) to BigInt`. #[connector_test( schema(schema_common), - exclude( - Postgres("pg.js", "neon.js", "pg.js.wasm", "neon.js.wasm"), - Vitess("planetscale.js", "planetscale.js.wasm") - ) + exclude(Postgres("pg.js", "neon.js", "pg.js.wasm", "neon.js.wasm")) )] async fn common_types(runner: Runner) -> TestResult<()> { create_common_children(&runner).await?; diff --git a/query-engine/driver-adapters/executor/package.json b/query-engine/driver-adapters/executor/package.json index dd1bff52d390..cf35f2997452 100644 --- a/query-engine/driver-adapters/executor/package.json +++ b/query-engine/driver-adapters/executor/package.json @@ -22,7 +22,7 @@ "dependencies": { "@libsql/client": "0.3.6", "@neondatabase/serverless": "0.7.2", - "@planetscale/database": "1.14.0", + "@planetscale/database": "1.15.0", "query-engine-wasm-latest": "npm:@prisma/query-engine-wasm@latest", "query-engine-wasm-baseline": "npm:@prisma/query-engine-wasm@0.0.19", "@prisma/adapter-libsql": "workspace:*",