type_bridge.migration.state¶
state
¶
Migration-state records, external-store protocol, and TypeDB default backend.
MigrationRecord
dataclass
¶
Record of an applied migration.
MigrationRunRecord
dataclass
¶
MigrationRunRecord(run_id, app_label, name, checksum, direction, status, started_at, finished_at=None, error=None, executor_ip=None, executor_mac=None)
Record of one migration execution attempt.
MigrationState
dataclass
¶
Complete state of applied migrations.
is_applied
¶
Check if a migration has been applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
name
|
str
|
Migration name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if migration has been applied |
Source code in type_bridge/migration/state.py
add
¶
Add a migration record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
MigrationRecord
|
Migration record to add |
required |
remove
¶
Remove a migration record (for rollback).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
name
|
str
|
Migration name |
required |
Source code in type_bridge/migration/state.py
get_latest
¶
Get the most recently applied migration for an app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
Returns:
| Type | Description |
|---|---|
MigrationRecord | None
|
Most recent migration record, or None |
Source code in type_bridge/migration/state.py
get_all_for_app
¶
Get all applied migrations for an app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
Returns:
| Type | Description |
|---|---|
list[MigrationRecord]
|
List of migration records in application order |
Source code in type_bridge/migration/state.py
MigrationStateStore
¶
Bases: Protocol
State operations required by :class:MigrationExecutor.
Implement this protocol to keep applied migration state outside the target
TypeDB database. Schema bootstrap and run-log reads are intentionally not
part of the contract: the default :class:MigrationStateManager provides
those TypeDB-specific capabilities, while embedding orchestrators may own
persistence and execution-attempt logging independently.
MigrationStateManager
¶
Manages migration state in TypeDB.
Applied state is stored in TypeDB as type_bridge_migration entities, and
execution attempts are stored as type_bridge_migration_run entities. The
storage mechanism — schema bootstrap, reads, and writes — lives in Rust
behind the MigrationStateStore seam; this class is a thin facade that
delegates to a Rust-owned PyMigrationStateManager and assembles Python
dataclasses for callers.
Example
manager = MigrationStateManager(db) state = manager.load_state()
if not state.is_applied("myapp", "0001_initial"): # Apply migration... manager.record_applied("myapp", "0001_initial", "abc123")
Initialize state manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database connection |
required |
Source code in type_bridge/migration/state.py
ensure_schema
¶
Ensure the migration tracking schema exists in TypeDB.
Idempotent: the Rust state store no-ops when the schema is already ensured, so no second Python-side latch is kept here.
Source code in type_bridge/migration/state.py
load_state
¶
Load migration state from TypeDB.
Returns:
| Type | Description |
|---|---|
MigrationState
|
Current migration state |
Source code in type_bridge/migration/state.py
load_runs
¶
Load the migration execution run log from TypeDB.
Source code in type_bridge/migration/state.py
record_applied
¶
Record that a migration was applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
name
|
str
|
Migration name |
required |
checksum
|
str
|
Migration content hash |
required |
Source code in type_bridge/migration/state.py
record_unapplied
¶
Record that a migration was rolled back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_label
|
str
|
Application label |
required |
name
|
str
|
Migration name |
required |
Source code in type_bridge/migration/state.py
record_run_started
¶
Record that one migration execution attempt started.
Source code in type_bridge/migration/state.py
record_run_finished
¶
Record that a migration execution attempt finished.