120 lines
4.0 KiB
Python
120 lines
4.0 KiB
Python
|
|
"""initial schema: surgery_final_results / surgery_result_details / voice_confirmation_audits
|
|||
|
|
|
|||
|
|
Revision ID: 0001_initial
|
|||
|
|
Revises:
|
|||
|
|
Create Date: 2026-04-23
|
|||
|
|
|
|||
|
|
对应 `app.db.models` 中的三张表,与 `init_db_schema()` 的 ``Base.metadata.create_all``
|
|||
|
|
等价,作为生产环境 `alembic upgrade head` 的初始版本。
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from typing import Sequence, Union
|
|||
|
|
|
|||
|
|
import sqlalchemy as sa
|
|||
|
|
from alembic import op
|
|||
|
|
|
|||
|
|
|
|||
|
|
revision: str = "0001_initial"
|
|||
|
|
down_revision: Union[str, None] = None
|
|||
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|||
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|||
|
|
|
|||
|
|
|
|||
|
|
def upgrade() -> None:
|
|||
|
|
op.create_table(
|
|||
|
|
"surgery_final_results",
|
|||
|
|
sa.Column("surgery_id", sa.String(length=6), primary_key=True),
|
|||
|
|
sa.Column(
|
|||
|
|
"completed_at",
|
|||
|
|
sa.DateTime(timezone=True),
|
|||
|
|
server_default=sa.text("CURRENT_TIMESTAMP"),
|
|||
|
|
nullable=False,
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
op.create_table(
|
|||
|
|
"surgery_result_details",
|
|||
|
|
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
|||
|
|
sa.Column(
|
|||
|
|
"surgery_id",
|
|||
|
|
sa.String(length=6),
|
|||
|
|
sa.ForeignKey(
|
|||
|
|
"surgery_final_results.surgery_id", ondelete="CASCADE"
|
|||
|
|
),
|
|||
|
|
nullable=False,
|
|||
|
|
index=True,
|
|||
|
|
),
|
|||
|
|
sa.Column("item_id", sa.String(length=256), nullable=False),
|
|||
|
|
sa.Column("item_name", sa.String(length=256), nullable=False),
|
|||
|
|
sa.Column("quantity", sa.Integer(), nullable=False),
|
|||
|
|
sa.Column("doctor_id", sa.String(length=128), nullable=False),
|
|||
|
|
sa.Column("recorded_at", sa.DateTime(timezone=True), nullable=False),
|
|||
|
|
sa.Column(
|
|||
|
|
"source", sa.String(length=32), nullable=False, server_default="vision"
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
op.create_index(
|
|||
|
|
op.f("ix_surgery_result_details_surgery_id"),
|
|||
|
|
"surgery_result_details",
|
|||
|
|
["surgery_id"],
|
|||
|
|
unique=False,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
op.create_table(
|
|||
|
|
"voice_confirmation_audits",
|
|||
|
|
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True),
|
|||
|
|
sa.Column("surgery_id", sa.String(length=6), nullable=False, index=True),
|
|||
|
|
sa.Column(
|
|||
|
|
"confirmation_id", sa.String(length=128), nullable=False, index=True
|
|||
|
|
),
|
|||
|
|
sa.Column("status", sa.String(length=32), nullable=False),
|
|||
|
|
sa.Column("audio_object_key", sa.String(length=512), nullable=True),
|
|||
|
|
sa.Column("audio_content_type", sa.String(length=128), nullable=True),
|
|||
|
|
sa.Column("audio_size_bytes", sa.Integer(), nullable=True),
|
|||
|
|
sa.Column("audio_sha256", sa.String(length=64), nullable=True),
|
|||
|
|
sa.Column("asr_text", sa.String(length=2048), nullable=True),
|
|||
|
|
sa.Column("resolved_label", sa.String(length=256), nullable=True),
|
|||
|
|
sa.Column("options_snapshot_json", sa.Text(), nullable=True),
|
|||
|
|
sa.Column("error_message", sa.String(length=1024), nullable=True),
|
|||
|
|
sa.Column(
|
|||
|
|
"created_at",
|
|||
|
|
sa.DateTime(timezone=True),
|
|||
|
|
server_default=sa.text("CURRENT_TIMESTAMP"),
|
|||
|
|
nullable=False,
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
op.create_index(
|
|||
|
|
op.f("ix_voice_confirmation_audits_surgery_id"),
|
|||
|
|
"voice_confirmation_audits",
|
|||
|
|
["surgery_id"],
|
|||
|
|
unique=False,
|
|||
|
|
)
|
|||
|
|
op.create_index(
|
|||
|
|
op.f("ix_voice_confirmation_audits_confirmation_id"),
|
|||
|
|
"voice_confirmation_audits",
|
|||
|
|
["confirmation_id"],
|
|||
|
|
unique=False,
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
|
|||
|
|
def downgrade() -> None:
|
|||
|
|
op.drop_index(
|
|||
|
|
op.f("ix_voice_confirmation_audits_confirmation_id"),
|
|||
|
|
table_name="voice_confirmation_audits",
|
|||
|
|
)
|
|||
|
|
op.drop_index(
|
|||
|
|
op.f("ix_voice_confirmation_audits_surgery_id"),
|
|||
|
|
table_name="voice_confirmation_audits",
|
|||
|
|
)
|
|||
|
|
op.drop_table("voice_confirmation_audits")
|
|||
|
|
|
|||
|
|
op.drop_index(
|
|||
|
|
op.f("ix_surgery_result_details_surgery_id"),
|
|||
|
|
table_name="surgery_result_details",
|
|||
|
|
)
|
|||
|
|
op.drop_table("surgery_result_details")
|
|||
|
|
|
|||
|
|
op.drop_table("surgery_final_results")
|