@@ -0,0 +1,101 @@
|
||||
"""Справочники норм RACION (NORMY_*).
|
||||
|
||||
Revision ID: lab_racion_normy
|
||||
Revises: lab_rnb_rename
|
||||
Create Date: 2026-06-10
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
revision = "lab_racion_normy"
|
||||
down_revision = "lab_rnb_rename"
|
||||
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 "lab_animal_profile" in insp.get_table_names():
|
||||
cols = {c["name"] for c in insp.get_columns("lab_animal_profile")}
|
||||
with op.batch_alter_table("lab_animal_profile", schema=None) as batch_op:
|
||||
if "norms_method" not in cols:
|
||||
batch_op.add_column(
|
||||
sa.Column("norms_method", sa.String(20), nullable=False, server_default="wesp")
|
||||
)
|
||||
if "norms_params_json" not in cols:
|
||||
batch_op.add_column(sa.Column("norms_params_json", sa.Text(), nullable=True))
|
||||
|
||||
if "lab_racion_normy_moskwa" not in insp.get_table_names():
|
||||
op.create_table(
|
||||
"lab_racion_normy_moskwa",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("npitv", sa.Integer(), nullable=False),
|
||||
sa.Column("pom", sa.Integer(), nullable=False, server_default="1"),
|
||||
sa.Column("koef", sa.Float(), nullable=True),
|
||||
sa.Column("popr_k_json", sa.Text(), nullable=True),
|
||||
sa.UniqueConstraint("npitv", "pom", name="uq_lab_racion_moskwa_npitv_pom"),
|
||||
)
|
||||
op.create_index("ix_lab_racion_normy_moskwa_npitv", "lab_racion_normy_moskwa", ["npitv"])
|
||||
|
||||
if "lab_racion_normy_moskwa_meta" not in insp.get_table_names():
|
||||
op.create_table(
|
||||
"lab_racion_normy_moskwa_meta",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("meta_key", sa.String(32), nullable=False),
|
||||
sa.Column("meta_json", sa.Text(), nullable=True),
|
||||
sa.UniqueConstraint("meta_key", name="uq_lab_racion_moskwa_meta_key"),
|
||||
)
|
||||
|
||||
if "lab_racion_normy_piter" not in insp.get_table_names():
|
||||
op.create_table(
|
||||
"lab_racion_normy_piter",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("npitv", sa.Integer(), nullable=False),
|
||||
sa.Column("konc", sa.Float(), nullable=False),
|
||||
sa.Column("udoy", sa.Float(), nullable=False),
|
||||
sa.Column("normy_json", sa.Text(), nullable=True),
|
||||
sa.UniqueConstraint("npitv", "konc", "udoy", name="uq_lab_racion_piter_npitv_konc_udoy"),
|
||||
)
|
||||
op.create_index("ix_lab_racion_normy_piter_npitv", "lab_racion_normy_piter", ["npitv"])
|
||||
|
||||
if "lab_racion_normy_piter_meta" not in insp.get_table_names():
|
||||
op.create_table(
|
||||
"lab_racion_normy_piter_meta",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("meta_key", sa.String(32), nullable=False),
|
||||
sa.Column("meta_json", sa.Text(), nullable=True),
|
||||
sa.UniqueConstraint("meta_key", name="uq_lab_racion_piter_meta_key"),
|
||||
)
|
||||
|
||||
if "lab_racion_normy_info" not in insp.get_table_names():
|
||||
op.create_table(
|
||||
"lab_racion_normy_info",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("nperem", sa.Integer(), nullable=False),
|
||||
sa.Column("znachenie_json", sa.Text(), nullable=True),
|
||||
sa.UniqueConstraint("nperem", name="uq_lab_racion_normy_info_nperem"),
|
||||
)
|
||||
op.create_index("ix_lab_racion_normy_info_nperem", "lab_racion_normy_info", ["nperem"])
|
||||
|
||||
|
||||
def downgrade(**kw) -> None:
|
||||
if kw.get("tag") == "reports":
|
||||
return
|
||||
bind = op.get_bind()
|
||||
insp = sa.inspect(bind)
|
||||
for table in (
|
||||
"lab_racion_normy_info",
|
||||
"lab_racion_normy_piter_meta",
|
||||
"lab_racion_normy_piter",
|
||||
"lab_racion_normy_moskwa_meta",
|
||||
"lab_racion_normy_moskwa",
|
||||
):
|
||||
if table in insp.get_table_names():
|
||||
op.drop_table(table)
|
||||
Reference in New Issue
Block a user