71 lines
3.2 KiB
Python
71 lines
3.2 KiB
Python
"""add human capacity overrides
|
|
|
|
Revision ID: 20260427_add_human_capacity_overrides
|
|
Revises: 20260426_add_pmflow_change_review_tables
|
|
Create Date: 2026-04-27
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
try:
|
|
from sqlalchemy.dialects.postgresql import JSONB
|
|
except Exception: # pragma: no cover
|
|
JSONB = sa.JSON
|
|
|
|
|
|
revision = "20260427_add_human_capacity_overrides"
|
|
down_revision = "20260426_add_pmflow_change_review_tables"
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def _json_type(bind):
|
|
return JSONB() if bind.dialect.name == "postgresql" else sa.JSON()
|
|
|
|
|
|
def _table_exists(bind, table_name: str) -> bool:
|
|
return sa.inspect(bind).has_table(table_name)
|
|
|
|
|
|
def upgrade() -> None:
|
|
bind = op.get_bind()
|
|
json_type = _json_type(bind)
|
|
|
|
if not _table_exists(bind, "human_capacity_overrides"):
|
|
op.create_table(
|
|
"human_capacity_overrides",
|
|
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
|
sa.Column("tenant_id", sa.BigInteger(), nullable=False),
|
|
sa.Column("created_at", sa.TIMESTAMP(), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("updated_at", sa.TIMESTAMP(), server_default=sa.func.now(), nullable=False),
|
|
sa.Column("project_id", sa.BigInteger(), sa.ForeignKey("projects.id"), nullable=False),
|
|
sa.Column("user_id", sa.BigInteger(), sa.ForeignKey("users.id"), nullable=False),
|
|
sa.Column("date", sa.Date(), nullable=False),
|
|
sa.Column("override_type", sa.String(length=32), nullable=False),
|
|
sa.Column("added_minutes", sa.Integer(), nullable=False, server_default="0"),
|
|
sa.Column("overtime_type", sa.String(length=32), nullable=True),
|
|
sa.Column("max_planned_utilization", sa.Float(), nullable=True),
|
|
sa.Column("work_type_bias", json_type, nullable=False),
|
|
sa.Column("high_risk_limit", sa.Integer(), nullable=True),
|
|
sa.Column("reason", sa.Text(), nullable=False),
|
|
sa.Column("expires_at", sa.TIMESTAMP(), nullable=False),
|
|
sa.Column("created_by", sa.BigInteger(), sa.ForeignKey("users.id"), nullable=False),
|
|
)
|
|
op.create_index("ix_human_capacity_overrides_tenant_id", "human_capacity_overrides", ["tenant_id"], unique=False)
|
|
op.create_index("ix_human_capacity_overrides_project_date", "human_capacity_overrides", ["project_id", "date"], unique=False)
|
|
op.create_index("ix_human_capacity_overrides_user_date", "human_capacity_overrides", ["user_id", "date"], unique=False)
|
|
op.create_index("ix_human_capacity_overrides_created_by", "human_capacity_overrides", ["created_by"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
bind = op.get_bind()
|
|
if _table_exists(bind, "human_capacity_overrides"):
|
|
op.drop_index("ix_human_capacity_overrides_created_by", table_name="human_capacity_overrides")
|
|
op.drop_index("ix_human_capacity_overrides_user_date", table_name="human_capacity_overrides")
|
|
op.drop_index("ix_human_capacity_overrides_project_date", table_name="human_capacity_overrides")
|
|
op.drop_index("ix_human_capacity_overrides_tenant_id", table_name="human_capacity_overrides")
|
|
op.drop_table("human_capacity_overrides")
|