Skip to content

type_bridge.migration.info

info

Schema information container for TypeDB schema management.

SchemaInfo

SchemaInfo()

Container for organized schema information.

Initialize SchemaInfo with empty collections.

Source code in type_bridge/migration/info.py
def __init__(self):
    """Initialize SchemaInfo with empty collections."""
    self.entities: list[type[Entity]] = []
    self.relations: list[type[Relation]] = []
    self.attribute_classes: set[type[Attribute]] = set()

get_entity_by_name

get_entity_by_name(name)

Get entity by type name.

Parameters:

Name Type Description Default
name str

Entity type name

required

Returns:

Type Description
type[Entity] | None

Entity class or None if not found

Source code in type_bridge/migration/info.py
def get_entity_by_name(self, name: str) -> type[Entity] | None:
    """Get entity by type name.

    Args:
        name: Entity type name

    Returns:
        Entity class or None if not found
    """
    for entity in self.entities:
        if entity.get_type_name() == name:
            return entity
    return None

get_relation_by_name

get_relation_by_name(name)

Get relation by type name.

Parameters:

Name Type Description Default
name str

Relation type name

required

Returns:

Type Description
type[Relation] | None

Relation class or None if not found

Source code in type_bridge/migration/info.py
def get_relation_by_name(self, name: str) -> type[Relation] | None:
    """Get relation by type name.

    Args:
        name: Relation type name

    Returns:
        Relation class or None if not found
    """
    for relation in self.relations:
        if relation.get_type_name() == name:
            return relation
    return None

validate

validate()

Validate schema definitions for TypeDB constraints.

Raises:

Type Description
SchemaValidationError

If schema violates TypeDB constraints

Source code in type_bridge/migration/info.py
def validate(self) -> None:
    """Validate schema definitions for TypeDB constraints.

    Raises:
        SchemaValidationError: If schema violates TypeDB constraints
    """
    # Validate entities
    for entity_model in self.entities:
        self._validate_no_duplicate_attribute_types(entity_model, entity_model.get_type_name())

    # Validate relations
    for relation_model in self.relations:
        self._validate_no_duplicate_attribute_types(
            relation_model, relation_model.get_type_name()
        )

to_typeql

to_typeql()

Generate TypeQL schema definition from collected schema information.

Base classes (with base=True) are skipped as they don't appear in TypeDB schema.

Validates the schema before generation.

Returns:

Type Description
str

TypeQL schema definition string

Raises:

Type Description
SchemaValidationError

If schema validation fails

Source code in type_bridge/migration/info.py
def to_typeql(self) -> str:
    """Generate TypeQL schema definition from collected schema information.

    Base classes (with base=True) are skipped as they don't appear in TypeDB schema.

    Validates the schema before generation.

    Returns:
        TypeQL schema definition string

    Raises:
        SchemaValidationError: If schema validation fails
    """
    self.validate()
    from type_bridge._rust_runtime import generate_define_block

    return generate_define_block(self.to_rust_schema_info())

compare

compare(other)

Compare this schema with another schema.

Parameters:

Name Type Description Default
other SchemaInfo

Another SchemaInfo to compare against

required

Returns:

Type Description
SchemaDiff

SchemaDiff containing all differences between the schemas

Source code in type_bridge/migration/info.py
def compare(self, other: "SchemaInfo") -> SchemaDiff:
    """Compare this schema with another schema.

    Args:
        other: Another SchemaInfo to compare against

    Returns:
        SchemaDiff containing all differences between the schemas
    """
    from type_bridge._rust_runtime import compute_schema_diff

    rust_diff = compute_schema_diff(self.to_rust_schema_info(), other.to_rust_schema_info())
    return from_rust_schema_diff(rust_diff, current_schema=self, target_schema=other)

to_rust_schema_info

to_rust_schema_info()

Serialize this Python model schema to the Rust SchemaInfo dict shape.

Registers all non-base entity and relation descriptors into a fresh PyDescriptorRegistry and delegates to Rust SchemaInfo::from_descriptors for the full projection: entity/relation entries, plays_cardinalities overlays, and foreign parent_type nulling all happen inside Rust.

The attributes section is merged on the Python side because it requires attribute-class metadata (regex, range, allowed_values, etc.) that is not represented in the descriptor layer.

Source code in type_bridge/migration/info.py
def to_rust_schema_info(self) -> dict:
    """Serialize this Python model schema to the Rust ``SchemaInfo`` dict shape.

    Registers all non-base entity and relation descriptors into a fresh
    ``PyDescriptorRegistry`` and delegates to Rust ``SchemaInfo::from_descriptors``
    for the full projection: entity/relation entries, plays_cardinalities overlays,
    and foreign parent_type nulling all happen inside Rust.

    The attributes section is merged on the Python side because it requires
    attribute-class metadata (regex, range, allowed_values, etc.) that is not
    represented in the descriptor layer.
    """
    from type_bridge._rust_runtime import (
        attribute_schema_entry,
        descriptor_for_model,
        rust_core,
    )

    registry = rust_core().PyDescriptorRegistry()
    for entity in self.entities:
        if _is_base_model(entity):
            continue
        registry.register_entity(descriptor_for_model(entity))
    for relation in self.relations:
        if _is_base_model(relation):
            continue
        registry.register_relation(descriptor_for_model(relation))

    info = registry.schema_info()

    # Merge attribute-class metadata. Rust from_descriptors emits only the
    # attr_name/value_type pairs it derives from owned_attributes; full
    # attribute-class metadata (regex, range, allowed_values, abstract,
    # independent, parent_type) requires the Python Attribute class.
    for entity in self.entities:
        if _is_base_model(entity):
            continue
        for attr_info in entity.get_all_attributes().values():
            entry = attribute_schema_entry(attr_info.typ)
            info["attributes"][entry["attr_name"]] = entry
    for relation in self.relations:
        if _is_base_model(relation):
            continue
        for attr_info in relation.get_all_attributes().values():
            entry = attribute_schema_entry(attr_info.typ)
            info["attributes"][entry["attr_name"]] = entry
    for attr_cls in self.attribute_classes:
        entry = attribute_schema_entry(attr_cls)
        info["attributes"][entry["attr_name"]] = entry

    return info