0d30c58bf0
Snapshot of the working tree on srv1071960 (branch main), taken during server cleanup. .env files, node_modules, builds, logs and media were excluded.
57 lines
2.4 KiB
Python
57 lines
2.4 KiB
Python
"""stockist visits on the Daily Call Report
|
|
|
|
Revision ID: a7e3f9b5c2d4
|
|
Revises: z6d2e8f4a1b3
|
|
Create Date: 2026-11-03
|
|
"""
|
|
|
|
from collections.abc import Sequence
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
revision: str = "a7e3f9b5c2d4"
|
|
down_revision: str | None = "z6d2e8f4a1b3"
|
|
branch_labels: str | Sequence[str] | None = None
|
|
depends_on: str | Sequence[str] | None = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"stockist_call",
|
|
sa.Column("id", sa.UUID(), nullable=False),
|
|
sa.Column("dcr_id", sa.UUID(), nullable=False),
|
|
sa.Column("stockist_id", sa.UUID(), nullable=False),
|
|
sa.Column("visit_time", sa.Time(), nullable=False),
|
|
sa.Column("pob", sa.String(length=100), nullable=True),
|
|
sa.Column("remarks", sa.Text(), nullable=True),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.ForeignKeyConstraint(["dcr_id"], ["daily_call_report.id"], ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["stockist_id"], ["stockist.id"], ondelete="RESTRICT"),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
sa.UniqueConstraint("dcr_id", "stockist_id", name="uq_call_dcr_stockist"),
|
|
)
|
|
|
|
op.add_column("missed_visit", sa.Column("stockist_id", sa.UUID(), nullable=True))
|
|
op.create_foreign_key(
|
|
"missed_visit_stockist_id_fkey", "missed_visit", "stockist", ["stockist_id"], ["id"], ondelete="RESTRICT"
|
|
)
|
|
op.create_unique_constraint("uq_missed_dcr_stockist", "missed_visit", ["dcr_id", "stockist_id"])
|
|
op.drop_constraint("ck_missed_one_target", "missed_visit", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_missed_one_target", "missed_visit", "num_nonnulls(doctor_id, chemist_id, stockist_id) = 1"
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.execute("DELETE FROM missed_visit WHERE stockist_id IS NOT NULL")
|
|
op.drop_constraint("ck_missed_one_target", "missed_visit", type_="check")
|
|
op.create_check_constraint(
|
|
"ck_missed_one_target", "missed_visit", "(doctor_id IS NULL) <> (chemist_id IS NULL)"
|
|
)
|
|
op.drop_constraint("uq_missed_dcr_stockist", "missed_visit", type_="unique")
|
|
op.drop_constraint("missed_visit_stockist_id_fkey", "missed_visit", type_="foreignkey")
|
|
op.drop_column("missed_visit", "stockist_id")
|
|
op.drop_table("stockist_call")
|