type_bridge.migration.registry¶
registry
¶
Model registry for migration auto-discovery.
This module provides a registry for tracking Entity/Relation models that should be included in migration auto-generation.
ModelRegistry
¶
Registry for tracking Entity/Relation models.
Models can be registered manually or auto-discovered from Python modules. The registry is used by the migration generator to determine which models should be tracked for schema changes.
Example - Manual registration
from type_bridge.migration import ModelRegistry from myapp.models import Person, Company
ModelRegistry.register(Person, Company)
Example - Auto-discovery
from type_bridge.migration import ModelRegistry
Discover all Entity/Relation classes in module¶
models = ModelRegistry.discover("myapp.models")
Example - In models.py (recommended pattern): from type_bridge import Entity, String, Flag, Key, TypeFlags from type_bridge.migration import ModelRegistry
class Name(String):
pass
class Person(Entity):
flags = TypeFlags(name="person")
name: Name = Flag(Key)
# Register at module load time
ModelRegistry.register(Person)
register
classmethod
¶
Register models for migration tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
type[Entity | Relation]
|
Entity or Relation classes to register |
()
|
Source code in type_bridge/migration/registry.py
unregister
classmethod
¶
clear
classmethod
¶
get_all
classmethod
¶
is_registered
classmethod
¶
Check if a model is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type
|
Model class to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if model is registered |
discover
classmethod
¶
Auto-discover Entity/Relation classes from a module.
Imports the module and finds all Entity/Relation subclasses defined in it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Python module path (e.g., "myapp.models") |
required |
register
|
bool
|
If True, also register discovered models |
True
|
Returns:
| Type | Description |
|---|---|
list[type[Entity | Relation]]
|
List of discovered Entity/Relation classes |
Raises:
| Type | Description |
|---|---|
ImportError
|
If module cannot be imported |
Source code in type_bridge/migration/registry.py
discover_recursive
classmethod
¶
Recursively discover models from a package.
Imports all modules in the package and discovers Entity/Relation classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_path
|
str
|
Python package path (e.g., "myapp") |
required |
register
|
bool
|
If True, also register discovered models |
True
|
Returns:
| Type | Description |
|---|---|
list[type[Entity | Relation]]
|
List of discovered Entity/Relation classes |
Raises:
| Type | Description |
|---|---|
ImportError
|
If package cannot be imported |