MCPcopy Create free account
hub / github.com/hashintel/hash / seed

Function seed

tests/graph/benches/util.rs:289–403  ·  view source on GitHub ↗
(
    store: &mut PostgresStore<C>,
    account_id: ActorEntityUuid,
    data_types: D,
    property_types: P,
    entity_types: E,
)

Source from the content-addressed store, hash-verified

287}
288
289pub async fn seed<D, P, E, C>(
290 store: &mut PostgresStore<C>,
291 account_id: ActorEntityUuid,
292 data_types: D,
293 property_types: P,
294 entity_types: E,
295) where
296 D: IntoIterator<Item = &'static str, IntoIter: Send> + Send,
297 P: IntoIterator<Item = &'static str, IntoIter: Send> + Send,
298 E: IntoIterator<Item = &'static str, IntoIter: Send> + Send,
299 C: AsClient,
300{
301 let domain_regex = Regex::new(
302 &std::env::var("HASH_GRAPH_ALLOWED_URL_DOMAIN_PATTERN")
303 .expect("HASH_GRAPH_ALLOWED_URL_DOMAIN_PATTERN must be set"),
304 )
305 .expect("HASH_GRAPH_ALLOWED_URL_DOMAIN_PATTERN must be a valid regex");
306
307 store
308 .create_data_types(
309 account_id,
310 data_types.into_iter().map(|data_type_str| {
311 let schema: DataType =
312 serde_json::from_str(data_type_str).expect("could not parse data type");
313
314 let ownership = if domain_regex.is_match(schema.id.base_url.as_str()) {
315 OntologyOwnership::Local {
316 web_id: WebId::new(account_id),
317 }
318 } else {
319 OntologyOwnership::Remote {
320 fetched_at: OffsetDateTime::now_utc(),
321 }
322 };
323
324 CreateDataTypeParams {
325 schema,
326 ownership,
327 conflict_behavior: ConflictBehavior::Skip,
328 provenance: ProvidedOntologyEditionProvenance {
329 actor_type: ActorType::User,
330 origin: OriginProvenance::from_empty_type(OriginType::Api),
331 sources: Vec::new(),
332 },
333 conversions: HashMap::new(),
334 }
335 }),
336 )
337 .await
338 .expect("should be able to create data types");
339
340 store
341 .create_property_types(
342 account_id,
343 property_types.into_iter().map(|property_type_str| {
344 let schema: PropertyType =
345 serde_json::from_str(property_type_str).expect("could not parse property type");
346

Callers 3

seed_dbFunction · 0.50
seed_dbFunction · 0.50
seed_dbFunction · 0.50

Calls 7

expectMethod · 0.45
create_data_typesMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
as_strMethod · 0.45
create_property_typesMethod · 0.45
create_entity_typesMethod · 0.45

Tested by

no test coverage detected