50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""Колонка valid_until для skip-таблиц (диапазон дат).
|
|
|
|
Revision ID: daily_skip_valid_until
|
|
Revises: daily_plan_part_skips
|
|
Create Date: 2026-06-07
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
|
|
revision = "daily_skip_valid_until"
|
|
down_revision = "daily_plan_part_skips"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
_TABLES = ("daily_trip_skip", "daily_ingredient_skip", "daily_unloading_group_skip")
|
|
|
|
|
|
def upgrade(**kw) -> None:
|
|
if kw.get("tag") == "reports":
|
|
return
|
|
bind = op.get_bind()
|
|
insp = sa.inspect(bind)
|
|
for table in _TABLES:
|
|
if table not in insp.get_table_names():
|
|
continue
|
|
cols = {c["name"] for c in insp.get_columns(table)}
|
|
if "valid_until" not in cols:
|
|
with op.batch_alter_table(table) as batch:
|
|
batch.add_column(sa.Column("valid_until", sa.Date(), nullable=True))
|
|
op.create_index(f"ix_{table}_valid_until", table, ["valid_until"], unique=False)
|
|
|
|
|
|
def downgrade(**kw) -> None:
|
|
if kw.get("tag") == "reports":
|
|
return
|
|
bind = op.get_bind()
|
|
insp = sa.inspect(bind)
|
|
for table in _TABLES:
|
|
if table not in insp.get_table_names():
|
|
continue
|
|
cols = {c["name"] for c in insp.get_columns(table)}
|
|
if "valid_until" in cols:
|
|
op.drop_index(f"ix_{table}_valid_until", table_name=table)
|
|
with op.batch_alter_table(table) as batch:
|
|
batch.drop_column("valid_until")
|