refactor: 移除审批和回写功能模块

移除了整个审批(approvals)和官方回写(writebacks)功能模块,
包括相关模型、路由、服务和配置项。更新了数据库迁移文件,
删除了相关的审批请求表和官方回写运行表。同时从API路由器中
移除了相应的路由,并调整了安全常量和字段验证器以匹配变更。
```
This commit is contained in:
2026-07-08 17:08:59 +08:00
parent 19e59e83cc
commit 0a153b264a
48 changed files with 135 additions and 2225 deletions

View File

@@ -5,13 +5,11 @@ from sqlalchemy import engine_from_config, pool
from app.core.config import get_settings
from app.core.db_base import Base
from app.modules.approvals import models as approval_models
from app.modules.audit import models as audit_models
from app.modules.business import models as business_models
from app.modules.events import models as event_models
from app.modules.feishu import models as feishu_models
from app.modules.workflows import models as workflow_models
from app.modules.writebacks import models as writeback_models
config = context.config
@@ -23,13 +21,11 @@ settings = get_settings()
# Keep imports referenced so SQLAlchemy model classes register with Base.metadata.
_REGISTERED_MODEL_MODULES = (
approval_models,
audit_models,
business_models,
event_models,
feishu_models,
workflow_models,
writeback_models,
)

View File

@@ -16,35 +16,6 @@ depends_on = None
def upgrade() -> None:
op.create_table(
"approval_requests",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True, nullable=False),
sa.Column("ticket_id", sa.String(length=64), nullable=False),
sa.Column("domain", sa.String(length=128), nullable=False),
sa.Column("record_id", sa.String(length=128), nullable=True),
sa.Column("action", sa.String(length=128), nullable=False),
sa.Column("applicant", sa.String(length=128), nullable=False),
sa.Column("approver", sa.String(length=128), nullable=True),
sa.Column("status", sa.String(length=32), nullable=False),
sa.Column("reason", sa.Text(), nullable=True),
sa.Column("payload", sa.Text(), nullable=True),
sa.Column("decision_comment", sa.Text(), nullable=True),
sa.Column("used_by", sa.String(length=128), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.Column("decided_at", sa.DateTime(), nullable=True),
sa.Column("used_at", sa.DateTime(), nullable=True),
)
op.create_index(op.f("ix_approval_requests_action"), "approval_requests", ['action'], unique=False)
op.create_index(op.f("ix_approval_requests_applicant"), "approval_requests", ['applicant'], unique=False)
op.create_index(op.f("ix_approval_requests_approver"), "approval_requests", ['approver'], unique=False)
op.create_index(op.f("ix_approval_requests_created_at"), "approval_requests", ['created_at'], unique=False)
op.create_index(op.f("ix_approval_requests_domain"), "approval_requests", ['domain'], unique=False)
op.create_index(op.f("ix_approval_requests_record_id"), "approval_requests", ['record_id'], unique=False)
op.create_index(op.f("ix_approval_requests_status"), "approval_requests", ['status'], unique=False)
op.create_index(op.f("ix_approval_requests_ticket_id"), "approval_requests", ['ticket_id'], unique=True)
op.create_index(op.f("ix_approval_requests_used_by"), "approval_requests", ['used_by'], unique=False)
op.create_table(
"attendance_records",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True, nullable=False),
@@ -205,37 +176,6 @@ def upgrade() -> None:
op.create_index(op.f("ix_legacy_sync_runs_started_at"), "legacy_sync_runs", ['started_at'], unique=False)
op.create_index(op.f("ix_legacy_sync_runs_status"), "legacy_sync_runs", ['status'], unique=False)
op.create_table(
"official_writeback_runs",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True, nullable=False),
sa.Column("code", sa.String(length=64), nullable=False),
sa.Column("domain", sa.String(length=128), nullable=False),
sa.Column("record_id", sa.String(length=128), nullable=True),
sa.Column("action", sa.String(length=128), nullable=False),
sa.Column("actor", sa.String(length=128), nullable=False),
sa.Column("status", sa.String(length=32), nullable=False),
sa.Column("approval_ticket_id", sa.String(length=64), nullable=True),
sa.Column("idempotency_key", sa.String(length=255), nullable=True),
sa.Column("request_payload", sa.JSON(), nullable=True),
sa.Column("provider_response", sa.JSON(), nullable=True),
sa.Column("error_message", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.Column("submitted_at", sa.DateTime(), nullable=True),
sa.Column("sent_at", sa.DateTime(), nullable=True),
)
op.create_index(op.f("ix_official_writeback_runs_action"), "official_writeback_runs", ['action'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_actor"), "official_writeback_runs", ['actor'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_approval_ticket_id"), "official_writeback_runs", ['approval_ticket_id'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_code"), "official_writeback_runs", ['code'], unique=True)
op.create_index(op.f("ix_official_writeback_runs_created_at"), "official_writeback_runs", ['created_at'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_domain"), "official_writeback_runs", ['domain'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_idempotency_key"), "official_writeback_runs", ['idempotency_key'], unique=True)
op.create_index(op.f("ix_official_writeback_runs_record_id"), "official_writeback_runs", ['record_id'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_sent_at"), "official_writeback_runs", ['sent_at'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_status"), "official_writeback_runs", ['status'], unique=False)
op.create_index(op.f("ix_official_writeback_runs_submitted_at"), "official_writeback_runs", ['submitted_at'], unique=False)
op.create_table(
"performance_metrics",
sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True, nullable=False),

View File

@@ -1,57 +1,19 @@
"""Add approval ticket consumption fields.
"""Remove obsolete approval ticket migration step.
Revision ID: 202607060002
Revises: 202607060001
Create Date: 2026-07-06
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy import inspect
revision = "202607060002"
down_revision = "202607060001"
branch_labels = None
depends_on = None
APPROVAL_REQUESTS_TABLE = "approval_requests"
USED_BY_COLUMN = "used_by"
USED_AT_COLUMN = "used_at"
def _column_names() -> set[str]:
inspector = inspect(op.get_bind())
return {
column["name"]
for column in inspector.get_columns(APPROVAL_REQUESTS_TABLE)
}
def upgrade() -> None:
columns = _column_names()
if USED_BY_COLUMN not in columns:
op.add_column(
APPROVAL_REQUESTS_TABLE,
sa.Column(USED_BY_COLUMN, sa.String(length=128), nullable=True),
)
op.create_index(
op.f("ix_approval_requests_used_by"),
APPROVAL_REQUESTS_TABLE,
[USED_BY_COLUMN],
unique=False,
)
if USED_AT_COLUMN not in columns:
op.add_column(
APPROVAL_REQUESTS_TABLE,
sa.Column(USED_AT_COLUMN, sa.DateTime(), nullable=True),
)
pass
def downgrade() -> None:
columns = _column_names()
if USED_BY_COLUMN in columns:
op.drop_index(op.f("ix_approval_requests_used_by"), table_name=APPROVAL_REQUESTS_TABLE)
op.drop_column(APPROVAL_REQUESTS_TABLE, USED_BY_COLUMN)
if USED_AT_COLUMN in columns:
op.drop_column(APPROVAL_REQUESTS_TABLE, USED_AT_COLUMN)
pass

View File

@@ -19,7 +19,6 @@ AUDIT_LOGS_TABLE = "audit_logs"
DOMAIN_EVENTS_TABLE = "domain_events"
WORKFLOW_INSTANCES_TABLE = "workflow_instances"
WORKFLOW_ACTIONS_TABLE = "workflow_actions"
OFFICIAL_WRITEBACK_RUNS_TABLE = "official_writeback_runs"
def _table_exists(table_name: str) -> bool:
@@ -154,48 +153,10 @@ def upgrade() -> None:
],
)
if not _table_exists(OFFICIAL_WRITEBACK_RUNS_TABLE):
op.create_table(
OFFICIAL_WRITEBACK_RUNS_TABLE,
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("code", sa.String(length=64), nullable=False),
sa.Column("domain", sa.String(length=128), nullable=False),
sa.Column("record_id", sa.String(length=128), nullable=True),
sa.Column("action", sa.String(length=128), nullable=False),
sa.Column("actor", sa.String(length=128), nullable=False),
sa.Column("status", sa.String(length=32), nullable=False),
sa.Column("approval_ticket_id", sa.String(length=64), nullable=True),
sa.Column("idempotency_key", sa.String(length=255), nullable=True),
sa.Column("request_payload", sa.JSON(), nullable=True),
sa.Column("provider_response", sa.JSON(), nullable=True),
sa.Column("error_message", sa.Text(), nullable=True),
sa.Column("created_at", sa.DateTime(), nullable=False),
sa.Column("updated_at", sa.DateTime(), nullable=False),
sa.Column("submitted_at", sa.DateTime(), nullable=True),
sa.Column("sent_at", sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
_create_indexes(
OFFICIAL_WRITEBACK_RUNS_TABLE,
[
("code", True),
("domain", False),
("record_id", False),
("action", False),
("actor", False),
("status", False),
("approval_ticket_id", False),
("idempotency_key", True),
("created_at", False),
("submitted_at", False),
("sent_at", False),
],
)
def downgrade() -> None:
for table_name in [
OFFICIAL_WRITEBACK_RUNS_TABLE,
WORKFLOW_ACTIONS_TABLE,
WORKFLOW_INSTANCES_TABLE,
DOMAIN_EVENTS_TABLE,