flask_more_smorest.sqla.migrations
Migration utilities for flask-more-smorest.
This module provides utilities for database migrations using Alembic. It handles the creation of migration environments and provides helpers for managing database schema changes.
Functions
|
Create a new migration file. |
|
Downgrade database to specified revision. |
|
Get list of migration revisions. |
|
Initialize Alembic migration environment for the application. |
|
Upgrade database to specified revision. |
- flask_more_smorest.sqla.migrations.init_migrations(app, directory='migrations')[source]
Initialize Alembic migration environment for the application.
Creates the migrations directory structure and configuration files needed for Alembic database migrations.
- Parameters:
- Return type:
Example
>>> from flask import Flask >>> from flask_more_smorest.sqla import init_migrations >>> >>> app = Flask(__name__) >>> init_migrations(app)
- flask_more_smorest.sqla.migrations.create_migration(message, directory='migrations')[source]
Create a new migration file.
Automatically detects changes in the database models and generates a migration script.
- Parameters:
- Raises:
RuntimeError – If migrations directory doesn’t exist
- Return type:
Example
>>> create_migration("Add user profile fields")
- flask_more_smorest.sqla.migrations.upgrade_database(revision='head', directory='migrations')[source]
Upgrade database to specified revision.
Applies database migrations up to the specified revision.
- Parameters:
- Return type:
Example
>>> upgrade_database() # Upgrade to latest >>> upgrade_database("ae1027a6acf") # Upgrade to specific revision
- flask_more_smorest.sqla.migrations.downgrade_database(revision, directory='migrations')[source]
Downgrade database to specified revision.
Reverts database migrations to the specified revision.
- Parameters:
- Return type:
Example
>>> downgrade_database("-1") # Downgrade one revision >>> downgrade_database("ae1027a6acf") # Downgrade to specific revision