type_bridge.migration.loader¶
loader
¶
Migration file loader and discovery.
Discovers and loads migration files from a directory structure. Migration files must follow the naming convention: NNNN_name.py (e.g., 0001_initial.py)
LoadedMigration
dataclass
¶
A migration loaded from a file.
Attributes:
| Name | Type | Description |
|---|---|---|
migration |
Migration
|
The Migration instance |
path |
Path
|
Path to the migration file |
checksum |
str
|
SHA256 hash of file content (first 16 chars) |
MigrationLoadError
¶
Bases: Exception
Error loading a migration file.
MigrationLoader
¶
Loads migration files from a directory.
Migration files must follow the naming pattern: NNNN_*.py where NNNN is a 4-digit number (e.g., 0001_initial.py, 0002_add_company.py)
Example
loader = MigrationLoader(Path("migrations")) migrations = loader.discover()
for loaded in migrations: print(f"{loaded.migration.name}: {loaded.checksum}")
Initialize loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
migrations_dir
|
Path
|
Directory containing migration files |
required |
Source code in type_bridge/migration/loader.py
discover
¶
Discover all migration files in order.
Returns:
| Type | Description |
|---|---|
list[LoadedMigration]
|
List of loaded migrations, sorted by filename |
Source code in type_bridge/migration/loader.py
get_by_name
¶
Get a specific migration by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Migration name (e.g., "0001_initial") |
required |
Returns:
| Type | Description |
|---|---|
LoadedMigration | None
|
LoadedMigration or None if not found |
Source code in type_bridge/migration/loader.py
get_by_number
¶
Get a specific migration by number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
int
|
Migration number (e.g., 1 for 0001_initial) |
required |
Returns:
| Type | Description |
|---|---|
LoadedMigration | None
|
LoadedMigration or None if not found |
Source code in type_bridge/migration/loader.py
get_next_number
¶
Get the next available migration number.
Returns:
| Type | Description |
|---|---|
int
|
Next migration number (1 if no migrations exist) |
Source code in type_bridge/migration/loader.py
validate_dependencies
¶
Validate that all migration dependencies are satisfied.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of error messages (empty if valid) |