Skip to content

type_bridge.migration.state_schema

state_schema

Public boundary for TypeBridge-owned migration-state schema objects.

MIGRATION_STATE_SCHEMA module-attribute

MIGRATION_STATE_SCHEMA = _label_projection(migration_state_schema())

Immutable labels for all schema objects owned by TypeBridge migration state.

MigrationStateSchema dataclass

MigrationStateSchema(entities, relations, attributes, roles)

Immutable label projection of the canonical migration-state schema.

Role labels are qualified as relation:role so an application relation can use the same unqualified role name without being classified as TypeBridge infrastructure.

migration_state_schema

migration_state_schema()

Return the full canonical migration-state schema descriptor from Rust.

Source code in type_bridge/migration/state_schema.py
def migration_state_schema() -> dict[str, Any]:
    """Return the full canonical migration-state schema descriptor from Rust."""
    return _rust_runtime.migration_state_schema()

is_migration_state_type

is_migration_state_type(*, kind, label)

Return whether label is a TypeBridge migration-state schema object.

Role labels must use the qualified relation:role form.

Source code in type_bridge/migration/state_schema.py
def is_migration_state_type(
    *,
    kind: Literal["entity", "relation", "attribute", "role"],
    label: str,
) -> bool:
    """Return whether ``label`` is a TypeBridge migration-state schema object.

    Role labels must use the qualified ``relation:role`` form.
    """
    return _rust_runtime.is_migration_state_type(kind, label)

without_migration_state_schema

without_migration_state_schema(schema)

Return a copy of schema without TypeBridge migration-state objects.

Source code in type_bridge/migration/state_schema.py
def without_migration_state_schema(schema: IntrospectedSchema) -> IntrospectedSchema:
    """Return a copy of ``schema`` without TypeBridge migration-state objects."""
    state_schema = MIGRATION_STATE_SCHEMA
    state_owners = state_schema.entities | state_schema.relations

    relations = {}
    for relation_name, relation in schema.relations.items():
        if relation_name in state_schema.relations:
            continue
        roles = {
            role_name: role
            for role_name, role in relation.roles.items()
            if f"{relation_name}:{role_name}" not in state_schema.roles
        }
        relations[relation_name] = replace(relation, roles=roles)

    return IntrospectedSchema(
        entities={
            name: entity
            for name, entity in schema.entities.items()
            if name not in state_schema.entities
        },
        relations=relations,
        attributes={
            name: attribute
            for name, attribute in schema.attributes.items()
            if name not in state_schema.attributes
        },
        ownerships=[
            ownership
            for ownership in schema.ownerships
            if ownership.owner_name not in state_owners
            and ownership.attribute_name not in state_schema.attributes
        ],
    )