Skip to content

Commit

Permalink
Merge branch 'main' into fix/tls-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln authored Sep 26, 2024
2 parents 4dd2736 + 031f4d3 commit f3c2658
Show file tree
Hide file tree
Showing 27 changed files with 130 additions and 38 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/test-query-engine-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
version:
type: string
required: true
ubuntu:
type: string
default: 'latest'
single_threaded:
type: boolean
default: false
Expand Down Expand Up @@ -46,7 +49,9 @@ jobs:
PRISMA_ENGINE_PROTOCOL: ${{ matrix.engine_protocol }}
PRISMA_RELATION_LOAD_STRATEGY: ${{ matrix.relation_load_strategy }}

runs-on: ubuntu-latest
runs-on: "ubuntu-20.04"
# TODO: Replace with the following once `[email protected]` is released.
# runs-on: "ubuntu-${{ inputs.ubuntu }}"
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-query-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,13 @@ jobs:
version: "2019"
- name: "mssql_2017"
version: "2017"
ubuntu: "20.04"
uses: ./.github/workflows/test-query-engine-template.yml
name: mssql ${{ matrix.database.version }}
with:
name: ${{ matrix.database.name }}
version: ${{ matrix.database.version }}
ubuntu: ${{ matrix.database.ubuntu }}
connector: "sqlserver"
relation_load_strategy: '["query"]'

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test-schema-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
database:
- name: mssql_2017
url: "sqlserver://localhost:1434;database=master;user=SA;password=<YourStrong@Passw0rd>;trustServerCertificate=true;socket_timeout=60;isolationLevel=READ UNCOMMITTED"
ubuntu: "20.04"
- name: mssql_2019
url: "sqlserver://localhost:1433;database=master;user=SA;password=<YourStrong@Passw0rd>;trustServerCertificate=true;socket_timeout=60;isolationLevel=READ UNCOMMITTED"
- name: mssql_2022
Expand Down Expand Up @@ -104,7 +105,9 @@ jobs:
is_vitess: true
single_threaded: true

runs-on: ubuntu-latest
runs-on: "ubuntu-20.04"
# TODO: Replace with the following once `[email protected]` is released.
# runs-on: "ubuntu-${{ matrix.database.ubuntu || 'latest' }}"
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
Expand Down
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ napi = { version = "2.15.1", default-features = false, features = [
napi-derive = "2.15.0"
js-sys = { version = "0.3" }
rand = { version = "0.8" }
regex = { version = "1", features = ["std"] }
serde_repr = { version = "0.1.17" }
serde-wasm-bindgen = { version = "0.5" }
tracing = { version = "0.1" }
Expand Down
2 changes: 1 addition & 1 deletion libs/prisma-value/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "0.1.0"
base64 = "0.13"
chrono.workspace = true
once_cell = "1.3"
regex = "1.2"
regex.workspace = true
bigdecimal = "0.3"
serde.workspace = true
serde_json.workspace = true
Expand Down
5 changes: 1 addition & 4 deletions libs/user-facing-errors/src/query_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ pub struct UniqueKeyViolation {
}

#[derive(Debug, UserFacingError, Serialize)]
#[user_facing(
code = "P2003",
message = "Foreign key constraint failed on the field: `{field_name}`"
)]
#[user_facing(code = "P2003", message = "Foreign key constraint violated: `{field_name}`")]
pub struct ForeignKeyViolation {
/// Field name from one model from Prisma schema
pub field_name: String,
Expand Down
2 changes: 1 addition & 1 deletion psl/psl-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ chrono = { workspace = true }
connection-string.workspace = true
itertools.workspace = true
once_cell = "1.3.1"
regex = "1.3.7"
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
enumflags2.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion psl/psl-core/src/common/preview_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ features!(
ReactNative,
PrismaSchemaFolder,
OmitApi,
TypedSql
TypedSql,
StrictUndefinedChecks
);

/// Generator preview features (alphabetically sorted)
Expand All @@ -100,6 +101,7 @@ pub const ALL_PREVIEW_FEATURES: FeatureMap = FeatureMap {
| RelationJoins
| OmitApi
| PrismaSchemaFolder
| StrictUndefinedChecks
}),
deprecated: enumflags2::make_bitflags!(PreviewFeature::{
AtomicNumberOperations
Expand Down
2 changes: 1 addition & 1 deletion psl/psl/tests/config/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn nice_error_for_unknown_generator_preview_feature() {
.unwrap_err();

let expectation = expect![[r#"
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi[0m
[1;91merror[0m: [1mThe preview feature "foo" is not known. Expected one of: deno, driverAdapters, fullTextIndex, fullTextSearch, metrics, multiSchema, nativeDistinct, postgresqlExtensions, tracing, views, relationJoins, prismaSchemaFolder, omitApi, strictUndefinedChecks[0m
--> schema.prisma:3
 | 
 2 |  provider = "prisma-client-js"
Expand Down
1 change: 1 addition & 0 deletions quaint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ futures = "0.3"
url.workspace = true
hex = "0.4"
itertools.workspace = true
regex.workspace = true

either = { version = "1.6" }
base64 = { version = "0.12.3" }
Expand Down
15 changes: 9 additions & 6 deletions quaint/src/connector/postgres/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use regex::Regex;
use std::fmt::{Display, Formatter};

use crate::error::{DatabaseConstraint, Error, ErrorKind, Name};
Expand Down Expand Up @@ -28,6 +29,12 @@ impl Display for PostgresError {
}
}

fn extract_fk_constraint_name(message: &str) -> Option<String> {
let re = Regex::new(r#"foreign key constraint "([^"]+)""#).unwrap();
re.captures(message)
.and_then(|caps| caps.get(1).map(|m| m.as_str().to_string()))
}

impl From<PostgresError> for Error {
fn from(value: PostgresError) -> Self {
match value.code.as_str() {
Expand Down Expand Up @@ -89,12 +96,8 @@ impl From<PostgresError> for Error {
builder.build()
}
None => {
let constraint = value
.message
.split_whitespace()
.nth(10)
.and_then(|s| s.split('"').nth(1))
.map(ToString::to_string)
// `value.message` looks like `update on table "Child" violates foreign key constraint "Child_parent_id_fkey"`
let constraint = extract_fk_constraint_name(value.message.as_str())
.map(DatabaseConstraint::Index)
.unwrap_or(DatabaseConstraint::CannotParse);

Expand Down
2 changes: 1 addition & 1 deletion query-engine/black-box-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ user-facing-errors.workspace = true
insta = "1.7.1"
enumflags2.workspace = true
query-engine-metrics = {path = "../metrics"}
regex = "1.9.3"
regex.workspace = true
4 changes: 2 additions & 2 deletions query-engine/connector-test-kit-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ drivers the code that actually communicates with the databases. See [`adapter-*`
To run tests through a driver adapters, you should also configure the following environment variables:

* `DRIVER_ADAPTER`: tells the test executor to use a particular driver adapter. Set to `neon`, `planetscale` or any other supported adapter.
* `DRIVER_ADAPTER_CONFIG`: a json string with the configuration for the driver adapter. This is adapter specific. See the [github workflow for driver adapter tests](.github/workflows/query-engine-driver-adapters.yml) for examples on how to configure the driver adapters.
* `DRIVER_ADAPTER_CONFIG`: a json string with the configuration for the driver adapter. This is adapter specific. See the [GitHub workflow for driver adapter tests](.github/workflows/query-engine-driver-adapters.yml) for examples on how to configure the driver adapters.
* `ENGINE`: can be used to run either `wasm` or `napi` or `c-abi` version of the engine.

Example:
Expand Down Expand Up @@ -339,7 +339,7 @@ run_query!(
**Accepting a snapshot update will replace, directly in your code, the expected output in the assertion.**
If you dislike the interactive view, you can also run `cargo insta accept` to automatically accept all snapshots and then use your git diff to check if everything is as intented.
If you dislike the interactive view, you can also run `cargo insta accept` to automatically accept all snapshots and then use your git diff to check if everything is as intended.
##### Without `cargo-insta`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ macro_rules! match_connector_result {
};
}

#[macro_export]
macro_rules! assert_connector_error {
($runner:expr, $q:expr, $code:expr, $( $($matcher:pat_param)|+ $( if $pred:expr )? => $msg:expr ),*) => {
use query_tests_setup::*;
use query_tests_setup::ConnectorVersion::*;

let connector = $runner.connector_version();

let mut results = match &connector {
$(
$( $matcher )|+ $( if $pred )? => $msg.to_string()
),*
};

if results.len() == 0 {
panic!("No assertion failure defined for connector {connector}.");
}

$runner.query($q).await?.assert_failure($code, Some(results));
};
}

#[macro_export]
macro_rules! is_one_of {
($result:expr, $potential_results:expr) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod one2one_req {
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -187,7 +187,7 @@ mod one2one_opt {
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -293,7 +293,7 @@ mod one2many_req {
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -397,7 +397,7 @@ mod one2many_opt {
runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod one2one_req {
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -182,7 +182,7 @@ mod one2one_opt {
&runner,
r#"mutation { updateOneParent(where: { id: 1 } data: { uniq: "u1" }) { id }}"#,
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -287,7 +287,7 @@ mod one2many_req {
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down Expand Up @@ -390,7 +390,7 @@ mod one2many_opt {
&runner,
r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#,
2003,
"Foreign key constraint failed on the field"
"Foreign key constraint violated"
);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod prisma_21901;
mod prisma_22007;
mod prisma_22298;
mod prisma_22971;
mod prisma_24072;
mod prisma_5952;
mod prisma_6173;
mod prisma_7010;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use indoc::indoc;
use query_engine_tests::*;

// Skip databases that don't support `onDelete: SetDefault`
#[test_suite(
schema(schema),
exclude(
MongoDb,
MySql(5.6),
MySql(5.7),
Vitess("planetscale.js"),
Vitess("planetscale.js.wasm")
)
)]
mod prisma_24072 {
fn schema() -> String {
let schema = indoc! {
r#"model Parent {
#id(id, Int, @id)
child Child?
}
model Child {
#id(id, Int, @id)
parent_id Int? @default(2) @unique
parent Parent? @relation(fields: [parent_id], references: [id], onDelete: NoAction)
}"#
};

schema.to_owned()
}

// Deleting the parent without cascading to the child should fail with an explicitly named constraint violation,
// without any "(not available)" names.
#[connector_test]
async fn test_24072(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, child: { create: { id: 1 }}}) { id }}"#),
@r###"{"data":{"createOneParent":{"id":1}}}"###
);

assert_connector_error!(
&runner,
"mutation { deleteOneParent(where: { id: 1 }) { id }}",
2003,
CockroachDb(_) | Postgres(_) | SqlServer(_) | Vitess(_) => "Foreign key constraint violated: `Child_parent_id_fkey (index)`",
MySql(_) => "Foreign key constraint violated: `parent_id`",
Sqlite(_) => "Foreign key constraint violated: `foreign key`",
_ => "Foreign key constraint violated"
);

Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ thiserror = "1.0"
async-trait.workspace = true
nom = "7.1"
itertools.workspace = true
regex = "1"
regex.workspace = true
serde.workspace = true
tracing.workspace = true
tracing-futures = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion query-engine/connectors/mongodb-query-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ itertools.workspace = true
mongodb.workspace = true
bson.workspace = true
rand.workspace = true
regex = "1"
regex.workspace = true
serde_json.workspace = true
thiserror = "1.0"
tokio.workspace = true
Expand Down
Loading

0 comments on commit f3c2658

Please sign in to comment.