type_bridge.migration.introspection¶
introspection
¶
TypeDB schema introspection for migration auto-generation.
This module provides functionality to introspect a TypeDB database schema and convert it to a format comparable with Python model definitions.
IntrospectedAttribute
dataclass
¶
An attribute type from the database schema.
IntrospectedOwnership
dataclass
¶
An ownership relationship between a type and an attribute.
IntrospectedRelation
dataclass
¶
A relation type from the database schema.
IntrospectedEntity
dataclass
¶
An entity type from the database schema.
IntrospectedSchema
dataclass
¶
Complete introspected schema from TypeDB database.
This is a database-centric view of the schema that can be compared against Python model definitions.
is_empty
¶
Check if the schema is empty (no custom types).
Source code in type_bridge/migration/introspection.py
get_entity_names
¶
get_relation_names
¶
get_attribute_names
¶
get_ownerships_for
¶
Get all ownerships for a specific owner type.
SchemaIntrospector
¶
Introspects TypeDB database schema.
Queries the database to discover all types, attributes, ownerships, and relations defined in the schema.
Example
introspector = SchemaIntrospector(db) schema = introspector.introspect()
print(f"Found {len(schema.entities)} entities") print(f"Found {len(schema.relations)} relations") print(f"Found {len(schema.attributes)} attributes")
Initialize introspector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database connection |
required |
Source code in type_bridge/migration/introspection.py
introspect_for_models
¶
Introspect database schema for specific model types.
This is the TypeDB 3.x compatible approach that checks each model type individually instead of enumerating all types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
list[type[Entity] | type[Relation]]
|
List of model classes to check |
required |
Returns:
| Type | Description |
|---|---|
IntrospectedSchema
|
IntrospectedSchema with info about existing types |
Source code in type_bridge/migration/introspection.py
introspect
¶
Query TypeDB schema and return structured info.
Returns:
| Type | Description |
|---|---|
IntrospectedSchema
|
IntrospectedSchema with all discovered types |
Source code in type_bridge/migration/introspection.py
compare_schemas
¶
Compare database schema against model type names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_schema
|
IntrospectedSchema
|
Introspected database schema |
required |
model_names
|
dict[str, str]
|
Dict mapping model class names to TypeDB type names |
required |
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dict with 'added', 'removed', 'unchanged' lists |