type_bridge.migration.generator¶
generator
¶
Migration generator for auto-generating migrations from model changes.
The generator is a thin adapter over the canonical Rust authoring core
(#166): it introspects the live base schema, collects the target schema
from the registered models, and delegates diffing, operation mapping,
.py/sidecar rendering, and snapshot generation to
:func:type_bridge.migration.author.author_migration. Live and offline
authoring therefore share exactly one SchemaDiff -> operations mapping.
MigrationGenerator
¶
Generates migration files from model changes.
Compares current models against the introspected database schema and delegates artifact authoring to the shared Rust core.
Example
generator = MigrationGenerator(db, Path("migrations"))
Generate migration from models¶
path = generator.generate([Person, Company, Employment], name="initial")
Creates: migrations/0001_initial.py¶
Generate empty migration for manual editing¶
path = generator.generate([], name="custom_changes", empty=True)
Initialize generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database connection |
required |
migrations_dir
|
Path
|
Directory to write migration files |
required |
Source code in type_bridge/migration/generator.py
generate
¶
Generate a migration file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
list[type[Entity | Relation]]
|
Model classes to check for changes |
required |
name
|
str
|
Migration name suffix (e.g., "initial", "add_company") |
'auto'
|
empty
|
bool
|
Create empty migration for manual editing |
False
|
Returns:
| Type | Description |
|---|---|
Path | None
|
Path to created file, or None if no changes detected |