type_bridge.migration.state¶
state
¶
Migration state tracking for TypeDB.
Tracks applied migrations in TypeDB as the sole source of truth.
MigrationRecord
dataclass
¶
Record of an applied migration.
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
MigrationStateManager
¶
Manages migration state in TypeDB.
State is stored in TypeDB as type_bridge_migration entities.
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 migration tracking schema exists in TypeDB.
Creates the type_bridge_migration entity type if it doesn't exist.
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
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 |