Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H-3424: Move ontology UUID identifier to typesystem #5372

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/hash-graph/libs/api/src/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ use time::OffsetDateTime;
use type_system::{
schema::{
ConversionDefinition, ConversionExpression, ConversionValue, Conversions, DataType,
DataTypeId, Operator, Variable,
DataTypeUuid, Operator, Variable,
},
url::{BaseUrl, OntologyTypeVersion, VersionedUrl},
};
Expand Down Expand Up @@ -805,7 +805,7 @@ where
.0
.into_iter()
.map(|request| {
let resource = DataTypeId::from_url(&request.resource);
let resource = DataTypeUuid::from_url(&request.resource);
(
resource,
(request.operation, resource, request.relation_and_subject),
Expand Down Expand Up @@ -878,7 +878,7 @@ where
Ok(Json(
authorization_api
.get_data_type_relations(
DataTypeId::from_url(&data_type_id),
DataTypeUuid::from_url(&data_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down Expand Up @@ -918,7 +918,7 @@ where
.check_data_type_permission(
actor_id,
permission,
DataTypeId::from_url(&data_type_id),
DataTypeUuid::from_url(&data_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down
14 changes: 7 additions & 7 deletions apps/hash-graph/libs/api/src/rest/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ use graph_type_defs::error::{ErrorInfo, Status, StatusPayloads};
use graph_types::{
account::EditionCreatedById,
ontology::{
EntityTypeEmbedding, EntityTypeId, EntityTypeMetadata, EntityTypeWithMetadata,
OntologyTemporalMetadata, OntologyTypeClassificationMetadata, OntologyTypeMetadata,
OntologyTypeReference, ProvidedOntologyEditionProvenance,
EntityTypeEmbedding, EntityTypeMetadata, EntityTypeWithMetadata, OntologyTemporalMetadata,
OntologyTypeClassificationMetadata, OntologyTypeMetadata, OntologyTypeReference,
ProvidedOntologyEditionProvenance,
},
owned_by_id::OwnedById,
};
Expand All @@ -52,7 +52,7 @@ use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
use time::OffsetDateTime;
use type_system::{
schema::EntityType,
schema::{EntityType, EntityTypeUuid},
url::{BaseUrl, OntologyTypeVersion, VersionedUrl},
};
use utoipa::{OpenApi, ToSchema};
Expand Down Expand Up @@ -216,7 +216,7 @@ where
.0
.into_iter()
.map(|request| {
let resource = EntityTypeId::from_url(&request.resource);
let resource = EntityTypeUuid::from_url(&request.resource);
(
resource,
(request.operation, resource, request.relation_and_subject),
Expand Down Expand Up @@ -289,7 +289,7 @@ where
Ok(Json(
authorization_api
.get_entity_type_relations(
EntityTypeId::from_url(&entity_type_id),
EntityTypeUuid::from_url(&entity_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down Expand Up @@ -329,7 +329,7 @@ where
.check_entity_type_permission(
actor_id,
permission,
EntityTypeId::from_url(&entity_type_id),
EntityTypeUuid::from_url(&entity_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down
10 changes: 5 additions & 5 deletions apps/hash-graph/libs/api/src/rest/property_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use graph::{
use graph_types::{
ontology::{
OntologyTemporalMetadata, OntologyTypeClassificationMetadata, OntologyTypeMetadata,
OntologyTypeReference, PropertyTypeEmbedding, PropertyTypeId, PropertyTypeMetadata,
OntologyTypeReference, PropertyTypeEmbedding, PropertyTypeMetadata,
PropertyTypeWithMetadata, ProvidedOntologyEditionProvenance,
},
owned_by_id::OwnedById,
Expand All @@ -49,7 +49,7 @@ use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
use time::OffsetDateTime;
use type_system::{
schema::PropertyType,
schema::{PropertyType, PropertyTypeUuid},
url::{OntologyTypeVersion, VersionedUrl},
};
use utoipa::{OpenApi, ToSchema};
Expand Down Expand Up @@ -792,7 +792,7 @@ where
.0
.into_iter()
.map(|request| {
let resource = PropertyTypeId::from_url(&request.resource);
let resource = PropertyTypeUuid::from_url(&request.resource);
(
resource,
(request.operation, resource, request.relation_and_subject),
Expand Down Expand Up @@ -865,7 +865,7 @@ where
Ok(Json(
authorization_api
.get_property_type_relations(
PropertyTypeId::from_url(&property_type_id),
PropertyTypeUuid::from_url(&property_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down Expand Up @@ -905,7 +905,7 @@ where
.check_property_type_permission(
actor_id,
permission,
PropertyTypeId::from_url(&property_type_id),
PropertyTypeUuid::from_url(&property_type_id),
Consistency::FullyConsistent,
)
.await
Expand Down
5 changes: 3 additions & 2 deletions apps/hash-graph/libs/graph/src/snapshot/entity/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use futures::{
channel::mpsc::{self, Receiver, Sender},
stream::{BoxStream, SelectAll, select_all},
};
use graph_types::{knowledge::entity::EntityUuid, ontology::EntityTypeId};
use graph_types::knowledge::entity::EntityUuid;
use type_system::schema::EntityTypeUuid;

use crate::{
snapshot::{EntitySnapshotRecord, SnapshotRestoreError, entity::EntityRowBatch},
Expand Down Expand Up @@ -107,7 +108,7 @@ impl Sink<EntitySnapshotRecord> for EntitySender {
self.is_of_type
.start_send_unpin(EntityIsOfTypeRow {
entity_edition_id: entity.metadata.record_id.edition_id,
entity_type_ontology_id: EntityTypeId::from_url(is_of_type),
entity_type_ontology_id: EntityTypeUuid::from_url(is_of_type),
})
.change_context(SnapshotRestoreError::Read)
.attach_printable("could not send entity type")?;
Expand Down
81 changes: 49 additions & 32 deletions apps/hash-graph/libs/graph/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ use futures::{
use graph_types::{
account::{AccountGroupId, AccountId},
knowledge::entity::{Entity, EntityId, EntityUuid},
ontology::{
DataTypeWithMetadata, EntityTypeId, EntityTypeWithMetadata, PropertyTypeId,
PropertyTypeWithMetadata,
},
ontology::{DataTypeWithMetadata, EntityTypeWithMetadata, PropertyTypeWithMetadata},
owned_by_id::OwnedById,
};
use hash_graph_store::filter::{Filter, QueryRecord};
use hash_status::StatusCode;
use postgres_types::ToSql;
use serde::{Deserialize, Serialize};
use tokio_postgres::error::SqlState;
use type_system::{schema::DataTypeId, url::VersionedUrl};
use type_system::{
schema::{DataTypeUuid, EntityTypeUuid, PropertyTypeUuid},
url::VersionedUrl,
};

use crate::{
snapshot::{
Expand Down Expand Up @@ -588,8 +588,8 @@ impl PostgresStorePool {
Ok(SnapshotEntry::DataType(Box::new(DataTypeSnapshotRecord {
schema: record.schema,
relations: authorization_api
.read_relations::<(DataTypeId, DataTypeRelationAndSubject)>(
RelationshipFilter::from_resource(DataTypeId::from_url(
.read_relations::<(DataTypeUuid, DataTypeRelationAndSubject)>(
RelationshipFilter::from_resource(DataTypeUuid::from_url(
&VersionedUrl::from(record.metadata.record_id.clone()),
)),
Consistency::FullyConsistent,
Expand All @@ -609,29 +609,46 @@ impl PostgresStorePool {

if settings.dump_property_types {
scope.spawn(
self.create_dump_stream::<PropertyTypeWithMetadata>()
.try_flatten_stream()
.and_then(move |record| async move {
Ok(SnapshotEntry::PropertyType(Box::new(PropertyTypeSnapshotRecord {
schema: record.schema,
relations: authorization_api
.read_relations::<(PropertyTypeId, PropertyTypeRelationAndSubject)>(
RelationshipFilter::from_resource(PropertyTypeId::from_url(
&VersionedUrl::from(record.metadata.record_id.clone()),
)),
Consistency::FullyConsistent,
)
.await
.change_context(SnapshotDumpError::Query)?
.map_ok(|(_, relation)| relation)
.try_collect()
.await
.change_context(SnapshotDumpError::Query)?,
metadata: record.metadata,
})))
})
.forward(snapshot_record_tx.clone()),
);
self.create_dump_stream::<PropertyTypeWithMetadata>()
.try_flatten_stream()
.and_then(move |record| async move {
Ok(
SnapshotEntry::PropertyType(
Box::new(
PropertyTypeSnapshotRecord {
schema: record.schema,
relations:
authorization_api
.read_relations::<(
PropertyTypeUuid,
PropertyTypeRelationAndSubject,
)>(
RelationshipFilter::from_resource(
PropertyTypeUuid::from_url(
&VersionedUrl::from(
record
.metadata
.record_id
.clone(),
),
),
),
Consistency::FullyConsistent,
)
.await
.change_context(SnapshotDumpError::Query)?
.map_ok(|(_, relation)| relation)
.try_collect()
.await
.change_context(SnapshotDumpError::Query)?,
metadata: record.metadata,
},
),
),
)
})
.forward(snapshot_record_tx.clone()),
);
}

if settings.dump_entity_types {
Expand All @@ -642,8 +659,8 @@ impl PostgresStorePool {
Ok(SnapshotEntry::EntityType(Box::new(EntityTypeSnapshotRecord {
schema: record.schema,
relations: authorization_api
.read_relations::<(EntityTypeId, EntityTypeRelationAndSubject)>(
RelationshipFilter::from_resource(EntityTypeId::from_url(
.read_relations::<(EntityTypeUuid, EntityTypeRelationAndSubject)>(
RelationshipFilter::from_resource(EntityTypeUuid::from_url(
&VersionedUrl::from(record.metadata.record_id.clone()),
)),
Consistency::FullyConsistent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use authorization::{
};
use error_stack::{Result, ResultExt};
use tokio_postgres::GenericClient;
use type_system::schema::DataTypeId;
use type_system::schema::DataTypeUuid;

use crate::{
snapshot::WriteBatch,
Expand All @@ -18,7 +18,7 @@ use crate::{
pub enum DataTypeRowBatch {
Schema(Vec<DataTypeRow>),
Conversions(Vec<DataTypeConversionsRow>),
Relations(HashMap<DataTypeId, Vec<DataTypeRelationAndSubject>>),
Relations(HashMap<DataTypeUuid, Vec<DataTypeRelationAndSubject>>),
Embeddings(Vec<DataTypeEmbeddingRow<'static>>),
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use futures::{
channel::mpsc::{self, Receiver, Sender},
stream::{BoxStream, SelectAll, select_all},
};
use type_system::{Valid, schema::DataTypeId};
use type_system::{Valid, schema::DataTypeUuid};

use crate::{
snapshot::{
Expand All @@ -32,7 +32,7 @@ pub struct DataTypeSender {
metadata: OntologyTypeMetadataSender,
schema: Sender<DataTypeRow>,
conversions: Sender<Vec<DataTypeConversionsRow>>,
relations: Sender<(DataTypeId, Vec<DataTypeRelationAndSubject>)>,
relations: Sender<(DataTypeUuid, Vec<DataTypeRelationAndSubject>)>,
}

// This is a direct wrapper around `Sink<mpsc::Sender<DataTypeRow>>` with and
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Sink<DataTypeSnapshotRecord> for DataTypeSender {
mut self: Pin<&mut Self>,
data_type: DataTypeSnapshotRecord,
) -> Result<(), Self::Error> {
let ontology_id = DataTypeId::from_url(&data_type.schema.id);
let ontology_id = DataTypeUuid::from_url(&data_type.schema.id);

self.metadata
.start_send_unpin(OntologyTypeMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ use authorization::{
};
use error_stack::{Result, ResultExt};
use futures::TryStreamExt;
use graph_types::ontology::EntityTypeId;
use postgres_types::{Json, ToSql};
use tokio_postgres::GenericClient;
use type_system::schema::EntityType;
use type_system::schema::{EntityType, EntityTypeUuid};

use crate::{
snapshot::WriteBatch,
Expand All @@ -28,7 +27,7 @@ pub enum EntityTypeRowBatch {
ConstrainsProperties(Vec<EntityTypeConstrainsPropertiesOnRow>),
ConstrainsLinks(Vec<EntityTypeConstrainsLinksOnRow>),
ConstrainsLinkDestinations(Vec<EntityTypeConstrainsLinkDestinationsOnRow>),
Relations(HashMap<EntityTypeId, Vec<EntityTypeRelationAndSubject>>),
Relations(HashMap<EntityTypeUuid, Vec<EntityTypeRelationAndSubject>>),
Embeddings(Vec<EntityTypeEmbeddingRow<'static>>),
}

Expand Down Expand Up @@ -247,7 +246,7 @@ where
.into_iter()
.map(|insertion| {
(
EntityTypeId::from_url(&insertion.schema.id).into_uuid(),
EntityTypeUuid::from_url(&insertion.schema.id).into_uuid(),
Json(insertion.closed_schema),
)
})
Expand Down
Loading
Loading