API¶
Anything documented here is part of the public API that Flask-Alembic provides, unless otherwise indicated. Anything not documented here is considered internal or private and may change at any time.
- class flask_alembic.Alembic(app=None, run_mkdir=True, command_name='db')¶
Provide an Alembic environment and migration API.
If instantiated without an app instance,
init_app()
is used to register an app at a later time.Configures basic logging to
stderr
for thesqlalchemy
andalembic
loggers if they do not already have handlers.- Parameters:
- init_app(app, run_mkdir=None, command_name=None)¶
Register this extension on an app. Will automatically set up migration directory by default.
Keyword arguments on this method override those set during
__init__()
if notNone
.
- rev_id()¶
Generate a unique id for a revision.
By default, this uses the current UTC timestamp. Override this method, or assign a static method, to change this.
Changelog
Changed in version 3.0: Uses the current UTC timestamp instead of a UUID.
- Return type:
- property script_directory: ScriptDirectory¶
Get the Alembic
ScriptDirectory
for the current app.
- property environment_context: EnvironmentContext¶
Get the Alembic
EnvironmentContext
for the current app.
- property migration_context: MigrationContext¶
Get the Alembic
MigrationContext
for the current app.Accessing this property opens a database connection but can’t close it automatically. Make sure to call
migration_context.connection.close()
when you’re done.
- property op: Operations¶
Get the Alembic
Operations
context for the current app.Accessing this property opens a database connection but can’t close it automatically. Make sure to call
migration_context.connection.close()
when you’re done.
- run_migrations(fn, **kwargs)¶
Configure an Alembic
MigrationContext
to run migrations for the given function.This takes the place of Alembic’s
env.py
file, specifically therun_migrations_online
function.
- mkdir()¶
Create the script directory and template.
- Return type:
None
- heads(resolve_dependencies=False)¶
Get the list of revisions that have no child revisions.
- branches()¶
Get the list of revisions that have more than one next revision.
- log(start='base', end='heads')¶
Get the list of revisions in the order they will run.
- stamp(target='heads')¶
Set the current database revision without running migrations.
- upgrade(target='heads')¶
Run migrations to upgrade database.
- downgrade(target=-1)¶
Run migrations to downgrade database.
- revision(message, empty=False, branch='default', parent='head', splice=False, depend=None, label=None, path=None)¶
Create a new revision. By default, auto-generate operations by comparing models and database.
- Parameters:
message (str) – Description of revision.
empty (bool) – Don’t auto-generate operations.
branch (str) – Use this independent branch name.
parent (t_rev) – Parent revision(s) of this revision.
splice (bool) – Allow non-head parent revision.
depend (t_rev | None) – Revision(s) this revision depends on.
label (str | list[str] | None) – Label(s) to apply to this revision.
path (str | None) – Where to store this revision.
- Returns:
List of new revisions.
- Return type:
list[Script | None]
- merge(revisions='heads', message=None, label=None)¶
Create a merge revision.
- Parameters:
- Returns:
A new revision object.
- Return type:
Script | None
- produce_migrations()¶
Generate the
MigrationScript
object that would generate a new revision.- Return type: