(
store: &mut PostgresStore<C>,
account_id: ActorEntityUuid,
data_types: D,
property_types: P,
entity_types: E,
)
| 287 | } |
| 288 | |
| 289 | pub 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 |
no test coverage detected