Skip to content

type_bridge.migration.base

base

Migration base class for TypeDB schema migrations.

MigrationDependency dataclass

MigrationDependency(app_label, migration_name)

Reference to another migration.

Example

dep = MigrationDependency("myapp", "0001_initial") str(dep) # "myapp.0001_initial"

Migration

Base class for migration scripts.

Migrations define schema changes that can be applied to a TypeDB database. They can be either model-based (for initial migrations) or operation-based (for incremental changes).

Model-based Migration Example

class InitialMigration(Migration): dependencies = [] models = [Person, Company, Employment]

Operation-based Migration Example

class AddPhoneMigration(Migration): dependencies = [("myapp", "0001_initial")] operations = [ ops.AddAttribute(Phone), ops.AddOwnership(Person, Phone, optional=True), ]

Attributes:

Name Type Description
name str

Migration name (auto-populated from filename)

app_label str

Application label (auto-populated from directory)

dependencies list[tuple[str, str]]

List of (app_label, migration_name) tuples

models list[type[Entity | Relation]]

List of Entity/Relation classes for initial migrations

operations list[Operation]

List of Operation instances for incremental migrations

reversible bool

Whether the migration can be rolled back

get_dependencies

get_dependencies()

Get dependencies as MigrationDependency objects.

Returns:

Type Description
list[MigrationDependency]

List of MigrationDependency instances

Source code in type_bridge/migration/base.py
def get_dependencies(self) -> list[MigrationDependency]:
    """Get dependencies as MigrationDependency objects.

    Returns:
        List of MigrationDependency instances
    """
    return [MigrationDependency(app, name) for app, name in self.dependencies]

describe

describe()

Generate a human-readable description of this migration.

Returns:

Type Description
str

Description string

Source code in type_bridge/migration/base.py
def describe(self) -> str:
    """Generate a human-readable description of this migration.

    Returns:
        Description string
    """
    if self.models:
        model_names = [m.__name__ for m in self.models]
        return f"Initial migration with models: {', '.join(model_names)}"
    elif self.operations:
        op_count = len(self.operations)
        return f"Migration with {op_count} operation(s)"
    else:
        return "Empty migration"