Migrations API¶
- class nextorm.migrations.MigrationRunner[source]¶
Bases:
objectObject-oriented wrapper for
makemigrations()andmigrate().Example:
runner = MigrationRunner(db, directory="migrations/") runner.makemigrations(name="add_tags") runner.migrate()
- class nextorm.migrations.MigrationStatus[source]¶
Bases:
objectStatus of a single migration file.
Attributes¶
- name:
The migration filename (e.g.
0001_initial.py).- version:
The stem of the filename without the
.pyextension (e.g.0001_initial).- applied:
Trueif 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.
- 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
Databasewith 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
Noneif there are no schema changes.
- 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).
- nextorm.migrations.showmigrations(db, *, directory='migrations')[source]¶
Return the status of every migration file in directory.
Each entry is a
MigrationStatusdescribing 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: