45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""web_user.lab_access — per-user доступ к модулю Lab.
|
|
|
|
Revision ID: web_user_lab_access
|
|
Revises: lab_racion_normy
|
|
Create Date: 2026-07-14
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision = "web_user_lab_access"
|
|
down_revision = "lab_racion_normy"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade(**kw) -> None:
|
|
if kw.get("tag") == "reports":
|
|
return
|
|
bind = op.get_bind()
|
|
insp = sa.inspect(bind)
|
|
if "web_user" not in insp.get_table_names():
|
|
return
|
|
cols = {c["name"] for c in insp.get_columns("web_user")}
|
|
if "lab_access" not in cols:
|
|
with op.batch_alter_table("web_user", schema=None) as batch_op:
|
|
batch_op.add_column(
|
|
sa.Column("lab_access", sa.Boolean(), nullable=False, server_default=sa.false())
|
|
)
|
|
|
|
|
|
def downgrade(**kw) -> None:
|
|
if kw.get("tag") == "reports":
|
|
return
|
|
bind = op.get_bind()
|
|
insp = sa.inspect(bind)
|
|
if "web_user" not in insp.get_table_names():
|
|
return
|
|
cols = {c["name"] for c in insp.get_columns("web_user")}
|
|
if "lab_access" in cols:
|
|
with op.batch_alter_table("web_user", schema=None) as batch_op:
|
|
batch_op.drop_column("lab_access")
|