Classes
Migration
3
▼
A single migration file.
Migration
3
▼
A single migration file.
Attributes
| Name | Type | Description |
|---|---|---|
version |
int
|
— |
name |
str
|
— |
sql |
str
|
— |
MigrationResult
4
▼
Result of running migrations.
MigrationResult
4
▼
Result of running migrations.
Attributes
| Name | Type | Description |
|---|---|---|
applied |
list[str]
|
— |
already_applied |
int
|
— |
total_available |
int
|
— |
Methods
summary
0
str
▼
property
summary
0
str
▼
def summary(self) -> str
Returns
str
Functions
_discover_migrations
1
list[Migration]
▼
Discover and parse migration files from a directory.
Files must match the patt…
_discover_migrations
1
list[Migration]
▼
def _discover_migrations(directory: str | Path) -> list[Migration]
Discover and parse migration files from a directory.
Files must match the patternNNN_description.sqlwhere NNN is
a zero-padded integer version number. Files are sorted by version.
Parameters
| Name | Type | Description |
|---|---|---|
directory |
str | Path |
Returns
list[Migration]
_ensure_tracking_table
1
None
▼
Create the migration tracking table if it doesn't exist.
async
_ensure_tracking_table
1
None
▼
async def _ensure_tracking_table(db: Database) -> None
Parameters
| Name | Type | Description |
|---|---|---|
db |
Database |
_get_applied_versions
1
set[int]
▼
Get the set of already-applied migration versions.
async
_get_applied_versions
1
set[int]
▼
async def _get_applied_versions(db: Database) -> set[int]
Parameters
| Name | Type | Description |
|---|---|---|
db |
Database |
Returns
set[int]
_apply_migration
2
None
▼
Apply a single migration.
Uses ``execute_script`` for SQLite to support multi-…
async
_apply_migration
2
None
▼
async def _apply_migration(db: Database, migration: Migration) -> None
Apply a single migration.
Usesexecute_scriptfor SQLite to support multi-statement migration
files (e.g. CREATE TABLE + CREATE INDEX in one file). The tracking
record is inserted separately after the migration succeeds.
Parameters
| Name | Type | Description |
|---|---|---|
db |
Database |
|
migration |
Migration |
migrate
2
MigrationResult
▼
Apply pending migrations from a directory.
Discovers ``.sql`` files, compares …
async
migrate
2
MigrationResult
▼
async def migrate(db: Database, directory: str | Path) -> MigrationResult
Apply pending migrations from a directory.
Discovers.sqlfiles, compares against the tracking table,
and applies missing migrations in version order. Each migration
runs in its own transaction.
Parameters
| Name | Type | Description |
|---|---|---|
db |
Database |
Connected database instance. |
directory |
str | Path |
Path to the migrations directory. |
Returns
MigrationResult