Skip to content

Commit

Permalink
H-3538: Move DataTypeStore into store (hashintel#5525)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored and JesusFileto committed Nov 5, 2024
1 parent bb33fc3 commit bb8728d
Show file tree
Hide file tree
Showing 59 changed files with 590 additions and 490 deletions.
1 change: 1 addition & 0 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 apps/hash-graph/bins/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ error-stack = { workspace = true }
graph = { workspace = true, features = ["clap"] }
graph-api = { workspace = true }
graph-types = { workspace = true }
hash-graph-store = { workspace = true }
hash-tracing = { workspace = true, features = ["clap"] }
temporal-client = { workspace = true }
test-server = { workspace = true, optional = true }
Expand Down
1 change: 1 addition & 0 deletions apps/hash-graph/bins/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@rust/graph": "0.0.0-private",
"@rust/graph-api": "0.0.0-private",
"@rust/graph-types": "0.0.0-private",
"@rust/hash-graph-store": "0.0.0-private",
"@rust/hash-tracing": "0.0.0-private",
"@rust/temporal-client": "0.0.0-private",
"@rust/test-server": "0.0.0-private",
Expand Down
16 changes: 11 additions & 5 deletions apps/hash-graph/bins/cli/src/subcommand/reindex_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use authorization::NoAuthorization;
use clap::Parser;
use error_stack::{Report, Result, ResultExt, ensure};
use graph::store::{
DataTypeStore, DatabaseConnectionInfo, DatabasePoolConfig, EntityStore, EntityTypeStore,
PostgresStorePool, StorePool,
DatabaseConnectionInfo, DatabasePoolConfig, PostgresStorePool, StorePool as _,
knowledge::EntityStore as _, ontology::EntityTypeStore as _,
};
use hash_graph_store::data_type::DataTypeStore as _;
use tokio_postgres::NoTls;

use crate::error::GraphError;
Expand Down Expand Up @@ -58,7 +59,8 @@ pub async fn reindex_cache(args: ReindexCacheArgs) -> Result<(), GraphError> {

if args.operations.data_types {
did_something = true;
DataTypeStore::reindex_data_type_cache(&mut store)
store
.reindex_data_type_cache()
.await
.change_context(GraphError)
.map_err(|report| {
Expand All @@ -69,7 +71,8 @@ pub async fn reindex_cache(args: ReindexCacheArgs) -> Result<(), GraphError> {

if args.operations.entity_types {
did_something = true;
EntityTypeStore::reindex_entity_type_cache(&mut store)
store
.reindex_entity_type_cache()
.await
.change_context(GraphError)
.map_err(|report| {
Expand All @@ -80,7 +83,8 @@ pub async fn reindex_cache(args: ReindexCacheArgs) -> Result<(), GraphError> {

if args.operations.entities {
did_something = true;
EntityStore::reindex_entity_cache(&mut store)
store
.reindex_entity_cache()
.await
.change_context(GraphError)
.map_err(|report| {
Expand All @@ -89,6 +93,8 @@ pub async fn reindex_cache(args: ReindexCacheArgs) -> Result<(), GraphError> {
})?;
}

drop(store);

ensure!(
did_something,
Report::new(GraphError).attach_printable(
Expand Down
18 changes: 10 additions & 8 deletions apps/hash-graph/libs/api/src/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ use graph::{
patch_id_and_parse,
},
store::{
DataTypeStore, OntologyVersionDoesNotExist, StorePool,
error::VersionedUrlAlreadyExists,
ontology::{
ArchiveDataTypeParams, CreateDataTypeParams, GetDataTypeSubgraphParams,
GetDataTypesParams, GetDataTypesResponse, UnarchiveDataTypeParams,
UpdateDataTypeEmbeddingParams, UpdateDataTypesParams,
},
StorePool,
error::{OntologyVersionDoesNotExist, VersionedUrlAlreadyExists},
},
};
use graph_types::{
Expand All @@ -42,7 +37,14 @@ use graph_types::{
},
owned_by_id::OwnedById,
};
use hash_graph_store::{ConflictBehavior, data_type::DataTypeQueryToken};
use hash_graph_store::{
ConflictBehavior,
data_type::{
ArchiveDataTypeParams, CreateDataTypeParams, DataTypeQueryToken, DataTypeStore as _,
GetDataTypeSubgraphParams, GetDataTypesParams, GetDataTypesResponse,
UnarchiveDataTypeParams, UpdateDataTypeEmbeddingParams, UpdateDataTypesParams,
},
};
use hash_status::Status;
use serde::{Deserialize, Serialize};
use temporal_client::TemporalClient;
Expand Down
8 changes: 4 additions & 4 deletions apps/hash-graph/libs/api/src/rest/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ use axum::{
};
use error_stack::{Report, ResultExt};
use graph::store::{
EntityQueryCursor, EntityQuerySorting, EntityQuerySortingRecord, EntityStore,
EntityValidationType, NullOrdering, Ordering, StorePool,
NullOrdering, Ordering, StorePool,
error::{EntityDoesNotExist, RaceConditionOnUpdate},
knowledge::{
CountEntitiesParams, CreateEntityRequest, DiffEntityParams, DiffEntityResult,
GetEntitiesParams, GetEntitiesResponse, GetEntitySubgraphParams, PatchEntityParams,
QueryConversion, UpdateEntityEmbeddingsParams, ValidateEntityParams,
EntityQueryCursor, EntityQuerySorting, EntityQuerySortingRecord, EntityStore as _,
EntityValidationType, GetEntitiesParams, GetEntitiesResponse, GetEntitySubgraphParams,
PatchEntityParams, QueryConversion, UpdateEntityEmbeddingsParams, ValidateEntityParams,
},
};
use graph_types::{
Expand Down
10 changes: 5 additions & 5 deletions apps/hash-graph/libs/api/src/rest/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ use graph::{
patch_id_and_parse,
},
store::{
EntityTypeStore, StorePool,
StorePool,
error::{BaseUrlAlreadyExists, OntologyVersionDoesNotExist, VersionedUrlAlreadyExists},
ontology::{
ArchiveEntityTypeParams, CreateEntityTypeParams, GetClosedMultiEntityTypeParams,
GetClosedMultiEntityTypeResponse, GetEntityTypeSubgraphParams, GetEntityTypesParams,
GetEntityTypesResponse, UnarchiveEntityTypeParams, UpdateEntityTypeEmbeddingParams,
UpdateEntityTypesParams,
ArchiveEntityTypeParams, CreateEntityTypeParams, EntityTypeStore as _,
GetClosedMultiEntityTypeParams, GetClosedMultiEntityTypeResponse,
GetEntityTypeSubgraphParams, GetEntityTypesParams, GetEntityTypesResponse,
UnarchiveEntityTypeParams, UpdateEntityTypeEmbeddingParams, UpdateEntityTypesParams,
},
},
};
Expand Down
9 changes: 5 additions & 4 deletions apps/hash-graph/libs/api/src/rest/property_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ use graph::{
patch_id_and_parse,
},
store::{
OntologyVersionDoesNotExist, PropertyTypeStore, StorePool,
error::VersionedUrlAlreadyExists,
StorePool,
error::{OntologyVersionDoesNotExist, VersionedUrlAlreadyExists},
ontology::{
ArchivePropertyTypeParams, CreatePropertyTypeParams, GetPropertyTypeSubgraphParams,
GetPropertyTypesParams, GetPropertyTypesResponse, UnarchivePropertyTypeParams,
UpdatePropertyTypeEmbeddingParams, UpdatePropertyTypesParams,
GetPropertyTypesParams, GetPropertyTypesResponse, PropertyTypeStore as _,
UnarchivePropertyTypeParams, UpdatePropertyTypeEmbeddingParams,
UpdatePropertyTypesParams,
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion apps/hash-graph/libs/api/src/rest/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
response::{IntoResponse, Response},
};
use error_stack::{Context, Report};
use graph::store::BaseUrlAlreadyExists;
use graph::store::error::BaseUrlAlreadyExists;
use hash_status::{Status, StatusCode};
use serde::Serialize;

Expand Down
14 changes: 9 additions & 5 deletions apps/hash-graph/libs/graph/src/snapshot/entity/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ use graph_types::{
},
ontology::OntologyTypeProvider,
};
use hash_graph_store::filter::Filter;
use hash_graph_store::{error::InsertionError, filter::Filter};
use tokio_postgres::GenericClient;
use type_system::schema::{ClosedEntityType, ClosedMultiEntityType};
use validation::{EntityPreprocessor, Validate, ValidateEntityComponents};

use crate::{
snapshot::WriteBatch,
store::{
AsClient, EntityStore, InsertionError, PostgresStore, StoreCache, StoreProvider,
StoreCache, StoreProvider,
crud::Read,
postgres::query::rows::{
EntityDraftRow, EntityEditionRow, EntityEmbeddingRow, EntityHasLeftEntityRow,
EntityHasRightEntityRow, EntityIdRow, EntityIsOfTypeRow, EntityTemporalMetadataRow,
knowledge::EntityStore as _,
postgres::{
AsClient, PostgresStore,
query::rows::{
EntityDraftRow, EntityEditionRow, EntityEmbeddingRow, EntityHasLeftEntityRow,
EntityHasRightEntityRow, EntityIdRow, EntityIsOfTypeRow, EntityTemporalMetadataRow,
},
},
},
};
Expand Down
11 changes: 9 additions & 2 deletions apps/hash-graph/libs/graph/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ use graph_types::{
ontology::{DataTypeWithMetadata, EntityTypeWithMetadata, PropertyTypeWithMetadata},
owned_by_id::OwnedById,
};
use hash_graph_store::filter::{Filter, QueryRecord};
use hash_graph_store::{
error::InsertionError,
filter::{Filter, QueryRecord},
};
use hash_status::StatusCode;
use postgres_types::ToSql;
use serde::{Deserialize, Serialize};
Expand All @@ -61,7 +64,11 @@ use crate::{
},
restore::SnapshotRecordBatch,
},
store::{AsClient, InsertionError, PostgresStore, PostgresStorePool, StorePool, crud::Read},
store::{
StorePool,
crud::Read,
postgres::{AsClient, PostgresStore, PostgresStorePool},
},
};

#[derive(Debug, Serialize, Deserialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use authorization::{
AuthorizationApi, backend::ZanzibarBackend, schema::DataTypeRelationAndSubject,
};
use error_stack::{Result, ResultExt};
use hash_graph_store::{data_type::DataTypeStore, error::InsertionError};
use tokio_postgres::GenericClient;
use type_system::schema::DataTypeUuid;

use crate::{
snapshot::WriteBatch,
store::{
AsClient, DataTypeStore, InsertionError, PostgresStore,
AsClient, PostgresStore,
postgres::query::rows::{DataTypeConversionsRow, DataTypeEmbeddingRow, DataTypeRow},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ use authorization::{
AuthorizationApi, backend::ZanzibarBackend, schema::EntityTypeRelationAndSubject,
};
use error_stack::{Result, ResultExt};
use hash_graph_store::error::InsertionError;
use tokio_postgres::GenericClient;
use type_system::schema::EntityTypeUuid;

use crate::{
snapshot::WriteBatch,
store::{
AsClient, EntityTypeStore as _, InsertionError, PostgresStore,
AsClient, PostgresStore,
ontology::EntityTypeStore as _,
postgres::query::rows::{EntityTypeEmbeddingRow, EntityTypeRow},
},
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use error_stack::{Result, ResultExt};
use hash_graph_store::error::InsertionError;
use tokio_postgres::GenericClient;

use crate::{
snapshot::WriteBatch,
store::{
AsClient, InsertionError, PostgresStore,
AsClient, PostgresStore,
postgres::query::rows::{
OntologyExternalMetadataRow, OntologyIdRow, OntologyOwnedMetadataRow,
OntologyTemporalMetadataRow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::collections::HashMap;

use authorization::{backend::ZanzibarBackend, schema::PropertyTypeRelationAndSubject};
use error_stack::{Result, ResultExt};
use hash_graph_store::error::InsertionError;
use tokio_postgres::GenericClient;
use type_system::schema::PropertyTypeUuid;

use crate::{
snapshot::WriteBatch,
store::{
AsClient, InsertionError, PostgresStore,
AsClient, PostgresStore,
postgres::query::rows::{
PropertyTypeConstrainsPropertiesOnRow, PropertyTypeConstrainsValuesOnRow,
PropertyTypeEmbeddingRow, PropertyTypeRow,
Expand Down
3 changes: 2 additions & 1 deletion apps/hash-graph/libs/graph/src/snapshot/owner/batch.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use authorization::{backend::ZanzibarBackend, schema::AccountGroupRelationAndSubject};
use error_stack::{Result, ResultExt};
use graph_types::account::AccountGroupId;
use hash_graph_store::error::InsertionError;
use tokio_postgres::GenericClient;

use crate::{
snapshot::{
WriteBatch,
owner::{AccountGroupRow, AccountRow},
},
store::{AsClient, InsertionError, PostgresStore},
store::{AsClient, PostgresStore},
};

pub enum AccountRowBatch {
Expand Down
3 changes: 2 additions & 1 deletion apps/hash-graph/libs/graph/src/snapshot/restore/batch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use authorization::{AuthorizationApi, backend::ZanzibarBackend};
use error_stack::Result;
use hash_graph_store::error::InsertionError;

use crate::{
snapshot::{
Expand All @@ -12,7 +13,7 @@ use crate::{
owner::AccountRowBatch,
web::WebBatch,
},
store::{AsClient, InsertionError, PostgresStore},
store::{AsClient, PostgresStore},
};

pub enum SnapshotRecordBatch {
Expand Down
3 changes: 2 additions & 1 deletion apps/hash-graph/libs/graph/src/snapshot/web/batch.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use authorization::{backend::ZanzibarBackend, schema::WebRelationAndSubject};
use error_stack::{Result, ResultExt};
use graph_types::owned_by_id::OwnedById;
use hash_graph_store::error::InsertionError;
use tokio_postgres::GenericClient;

use crate::{
snapshot::WriteBatch,
store::{AsClient, InsertionError, PostgresStore, postgres::query::rows::WebRow},
store::{AsClient, PostgresStore, postgres::query::rows::WebRow},
};

pub enum WebBatch {
Expand Down
3 changes: 1 addition & 2 deletions apps/hash-graph/libs/graph/src/store/crud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
use error_stack::Result;
use futures::{Stream, TryFutureExt, TryStreamExt};
use hash_graph_store::{
error::QueryError,
filter::{Filter, QueryRecord},
subgraph::{SubgraphRecord, temporal_axes::QueryTemporalAxes},
};
use tracing::instrument;
use type_system::url::VersionedUrl;

use crate::store::QueryError;

pub trait QueryResult<R, S: Sorting> {
type Indices: Send;

Expand Down
36 changes: 0 additions & 36 deletions apps/hash-graph/libs/graph/src/store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,6 @@ impl fmt::Display for StoreError {
}
}

#[derive(Debug)]
#[must_use]
pub struct InsertionError;

impl fmt::Display for InsertionError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("Could not insert into store")
}
}

impl Context for InsertionError {}

#[derive(Debug, Clone)]
#[must_use]
pub struct QueryError;

impl fmt::Display for QueryError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("Could not query from store")
}
}

impl Context for QueryError {}

#[derive(Debug)]
#[must_use]
pub struct UpdateError;

impl fmt::Display for UpdateError {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str("Could not update store")
}
}

impl Context for UpdateError {}

#[derive(Debug)]
#[must_use]
pub struct DeletionError;
Expand Down
Loading

0 comments on commit bb8728d

Please sign in to comment.