Migrations API

class nextorm.migrations.MigrationRunner[source]

Bases: object

Object-oriented wrapper for makemigrations() and migrate().

Example:

runner = MigrationRunner(db, directory="migrations/")
runner.makemigrations(name="add_tags")
runner.migrate()
__init__(db, *, directory='migrations')[source]
Parameters:
Return type:

None

makemigrations(name='migration')[source]

Write a new migration file if there are schema changes.

Parameters:

name (str)

Return type:

Path | None

migrate(*, fake=False)[source]

Apply all pending migrations.

Parameters:

fake (bool)

Return type:

list[str]

showmigrations()[source]

Return the status of every migration file in the migrations directory.

Return type:

list[MigrationStatus]

class nextorm.migrations.MigrationStatus[source]

Bases: object

Status of a single migration file.

Attributes

name:

The migration filename (e.g. 0001_initial.py).

version:

The stem of the filename without the .py extension (e.g. 0001_initial).

applied:

True if the migration has been recorded in the tracking table.

applied_at:

ISO‑8601 timestamp string recorded when the migration was applied, or an empty string when not yet applied.

__init__(name, version, applied, applied_at)[source]
Parameters:
Return type:

None

name
version
applied
applied_at
nextorm.migrations.makemigrations(db, name='migration', *, directory='migrations')[source]

Diff the entity schema against the last snapshot and write a migration file.

Parameters

db:

A bound Database with schema already built.

name:

Human-readable suffix for the migration filename.

directory:

Filesystem directory where migration files are stored.

Returns

Path

The path of the newly written migration file, or None if there are no schema changes.

Parameters:
Return type:

Path | None

nextorm.migrations.migrate(db, *, directory='migrations', fake=False)[source]

Apply all pending migration files in directory.

Parameters

db:

A bound, connected Database.

directory:

Directory containing migration files.

fake:

If True, record each migration as applied without executing the SQL.

Returns

list[str]

The names of migration files that were applied (or faked).

Parameters:
Return type:

list[str]

nextorm.migrations.showmigrations(db, *, directory='migrations')[source]

Return the status of every migration file in directory.

Each entry is a MigrationStatus describing whether the migration has been applied and, if so, when.

Parameters

db:

A bound, connected Database.

directory:

Directory containing migration files.

Returns

list[MigrationStatus]

One entry per migration file, in ascending version order. When the tracking table does not exist yet, all migrations are reported as pending.

Parameters:
Return type:

list[MigrationStatus]