Files
CosScene/server/alembic/versions/f1a2b3c4d5e6_add_system_configs.py
T
2026-05-09 16:40:29 +08:00

90 lines
4.0 KiB
Python

"""add_system_configs
Revision ID: f1a2b3c4d5e6
Revises: e9f8b1234cde
Create Date: 2026-04-12 20:40:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
revision: str = "f1a2b3c4d5e6"
down_revision: Union[str, None] = "e9f8b1234cde"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table(
"system_configs",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("config_key", sa.String(length=100), nullable=False),
sa.Column("category", sa.String(length=50), nullable=False),
sa.Column("title", sa.String(length=200), nullable=False),
sa.Column("config_json", sa.Text(), nullable=False, server_default="{}"),
sa.Column("description", sa.Text(), nullable=True),
sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.text("true")),
sa.Column("sort_order", sa.Integer(), nullable=False, server_default="0"),
sa.Column("updated_by", sa.Integer(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("config_key"),
)
op.create_index(op.f("ix_system_configs_config_key"), "system_configs", ["config_key"], unique=True)
op.create_index(op.f("ix_system_configs_category"), "system_configs", ["category"], unique=False)
op.create_index(op.f("ix_system_configs_is_active"), "system_configs", ["is_active"], unique=False)
system_configs_table = sa.table(
"system_configs",
sa.column("config_key", sa.String(length=100)),
sa.column("category", sa.String(length=50)),
sa.column("title", sa.String(length=200)),
sa.column("config_json", sa.Text()),
sa.column("description", sa.Text()),
sa.column("is_active", sa.Boolean()),
sa.column("sort_order", sa.Integer()),
)
op.bulk_insert(
system_configs_table,
[
{
"config_key": "notification_template_default",
"category": "notification_template",
"title": "默认通知模板",
"config_json": '{"type":"system","title_template":"{title}","content_template":"{content}","channels":["in_app"]}',
"description": "系统默认通知模板(JSON字符串)",
"is_active": True,
"sort_order": 1,
},
{
"config_key": "notification_rule_auto_dispatch",
"category": "notification_rule",
"title": "通知自动触发规则",
"config_json": '{"enabled":true,"triggers":[{"event":"report_resolved","template":"notification_template_default"}],"rate_limit_per_minute":60}',
"description": "通知规则引擎配置(JSON字符串)",
"is_active": True,
"sort_order": 2,
},
{
"config_key": "report_sop_default",
"category": "report_sop",
"title": "举报处理SOP",
"config_json": '{"steps":[{"status":"pending","action":"初筛"},{"status":"processing","action":"调查取证"},{"status":"resolved","action":"处置并回执"},{"status":"rejected","action":"驳回并说明"}],"sla_hours":24}',
"description": "举报工单标准化流程(JSON字符串)",
"is_active": True,
"sort_order": 3,
},
],
)
def downgrade() -> None:
op.drop_index(op.f("ix_system_configs_is_active"), table_name="system_configs")
op.drop_index(op.f("ix_system_configs_category"), table_name="system_configs")
op.drop_index(op.f("ix_system_configs_config_key"), table_name="system_configs")
op.drop_table("system_configs")