type_bridge.migration.base¶
base
¶
Migration base class for TypeDB schema migrations.
MigrationDependency
dataclass
¶
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 as MigrationDependency objects.
Returns:
| Type | Description |
|---|---|
list[MigrationDependency]
|
List of MigrationDependency instances |
describe
¶
Generate a human-readable description of this migration.
Returns:
| Type | Description |
|---|---|
str
|
Description string |