使用alembic的多模式postgres迁移
alembic-multischema的Python项目详细描述
alembic多模式
此模块提供在使用alembic时同时对多个postgres模式执行操作的能力。在
功能:
perSchema(**kwargs)
用于修饰迁移中的upgrade()和degrade()函数。当使用perSchema()修饰升级或降级时,将为当前数据库中的模式列表调用修饰函数。在
kwargs:
- 模式 运行函数所依据的架构名称的列表。如果省略perSchema()将使用getAllNonSystemSchemas()从当前数据库自动生成非系统架构列表
- 排除 运行函数时要排除的架构名称列表
getAllSchemas()
返回当前数据库中所有架构的列表。在
kwargs:
- 排除 运行函数时要排除的架构名称列表
getAllNonSystemSchemas()
返回当前数据库中的架构列表,忽略信息“架构”和“目录”。在
kwargs:
- 排除 运行函数时要排除的架构名称列表
用法示例:
"""CreateUsersTable
Revision ID: a6a219646b55
Revises:
Create Date: 2019-10-16 14:43:11.347575
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
from almebic_multischema import perSchema
# revision identifiers, used by Alembic.
revision = 'a6a219646b55'
down_revision = None
branch_labels = None
depends_on = None
@perSchema(schemas=["public", "foo", "bar"])
def upgrade():
users = text(
"""CREATE TABLE users
(
id serial PRIMARY KEY,
firstname VARCHAR (50) UNIQUE,
lastname VARCHAR (50)
);
""")
op.execute(users)
@perSchema(schemas=["public", "foo", "bar"])
def downgrade():
op.execute(text("DROP TABLE users"))
- 项目
标签: