From 8fbd3f317baa3a23bf502c022ac612f5a155570c Mon Sep 17 00:00:00 2001 From: David Overton Date: Thu, 13 Jun 2024 16:35:31 +1000 Subject: [PATCH 1/4] Don't require _id field to have type ObjectId when generate primary uniqueness constraint --- crates/configuration/src/configuration.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/configuration/src/configuration.rs b/crates/configuration/src/configuration.rs index 8c645515..8dfdfcbb 100644 --- a/crates/configuration/src/configuration.rs +++ b/crates/configuration/src/configuration.rs @@ -282,14 +282,10 @@ fn get_primary_key_uniqueness_constraint( name: &str, collection_type: &str, ) -> Option<(String, ndc::UniquenessConstraint)> { - // Check to make sure our collection's object type contains the _id objectid field + // Check to make sure our collection's object type contains the _id field // If it doesn't (should never happen, all collections need an _id column), don't generate the constraint let object_type = object_types.get(collection_type)?; - let id_field = object_type.fields.get("_id")?; - match &id_field.r#type { - schema::Type::Scalar(BsonScalarType::ObjectId) => Some(()), - _ => None, - }?; + let _id_field = object_type.fields.get("_id")?; let uniqueness_constraint = ndc::UniquenessConstraint { unique_columns: vec!["_id".into()], }; From 39939c6b70638f43519b13134964342625525c6c Mon Sep 17 00:00:00 2001 From: David Overton Date: Thu, 13 Jun 2024 16:38:19 +1000 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6efc455..8eb7d42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ This changelog documents the changes between release versions. - Support for root collection column references ([#75](https://github.com/hasura/ndc-mongodb/pull/75)) - Fix for databases with field names that begin with a dollar sign, or that contain dots ([#74](https://github.com/hasura/ndc-mongodb/pull/74)) - Implement column-to-column comparisons within the same collection ([#74](https://github.com/hasura/ndc-mongodb/pull/74)) +- Don't require _id field to have type ObjectId when generating primary uniqueness constraint ([#79](https://github.com/hasura/ndc-mongodb/pull/79)) ## [0.0.6] - 2024-05-01 - Enables logging events from the MongoDB driver by setting the `RUST_LOG` variable ([#67](https://github.com/hasura/ndc-mongodb/pull/67)) From 01186c8a678364197bff10f427a8f6b167be41dd Mon Sep 17 00:00:00 2001 From: David Overton Date: Thu, 13 Jun 2024 17:07:59 +1000 Subject: [PATCH 3/4] Require comparable scalar type for _id --- crates/configuration/src/configuration.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/configuration/src/configuration.rs b/crates/configuration/src/configuration.rs index 8dfdfcbb..6603f392 100644 --- a/crates/configuration/src/configuration.rs +++ b/crates/configuration/src/configuration.rs @@ -285,7 +285,11 @@ fn get_primary_key_uniqueness_constraint( // Check to make sure our collection's object type contains the _id field // If it doesn't (should never happen, all collections need an _id column), don't generate the constraint let object_type = object_types.get(collection_type)?; - let _id_field = object_type.fields.get("_id")?; + let id_field = object_type.fields.get("_id")?; + match &id_field.r#type { + schema::Type::Scalar(scalar_type) if scalar_type.is_comparable() => Some(()), + _ => None, + }?; let uniqueness_constraint = ndc::UniquenessConstraint { unique_columns: vec!["_id".into()], }; From 7bc7374fb397305e788d4b833fe0e752e3c934e1 Mon Sep 17 00:00:00 2001 From: Jesse Hallett Date: Thu, 13 Jun 2024 10:23:49 -0700 Subject: [PATCH 4/4] remove unused import to get clippy check passing --- crates/configuration/src/configuration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/configuration/src/configuration.rs b/crates/configuration/src/configuration.rs index 6603f392..5ff06eaa 100644 --- a/crates/configuration/src/configuration.rs +++ b/crates/configuration/src/configuration.rs @@ -2,7 +2,6 @@ use std::{collections::BTreeMap, path::Path}; use anyhow::{anyhow, ensure}; use itertools::Itertools; -use mongodb_support::BsonScalarType; use ndc_models as ndc; use serde::{Deserialize, Serialize};