"""新增精益管理培训周任务、完成事实和提醒审计。""" from alembic import op import sqlalchemy as sa revision = "p1a2b3c4d5e6" down_revision = "n8f9a0b1c2d3" branch_labels = None depends_on = None def upgrade() -> None: """创建精益培训业务表。""" op.create_table( "lean_training_weekly_tasks", sa.Column("id", sa.Integer(), nullable=False), sa.Column("config_id", sa.Integer(), nullable=False), sa.Column("week_key", sa.String(length=10), nullable=False), sa.Column("due_at", sa.DateTime(), nullable=False), sa.Column("video_resource_ids", sa.JSON(), nullable=False), sa.Column("target_roles", sa.JSON(), nullable=False), sa.Column("target_user_ids", sa.JSON(), nullable=False), sa.Column("status", sa.String(length=20), nullable=False), sa.Column("created_by_id", sa.Integer(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["config_id"], ["training_configs.id"]), sa.ForeignKeyConstraint(["created_by_id"], ["users.id"]), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("week_key", name="uq_lean_training_week_key"), ) op.create_index("ix_lean_training_weekly_tasks_config_id", "lean_training_weekly_tasks", ["config_id"]) op.create_index("ix_lean_training_weekly_tasks_week_key", "lean_training_weekly_tasks", ["week_key"]) op.create_index("ix_lean_training_weekly_tasks_due_at", "lean_training_weekly_tasks", ["due_at"]) op.create_index("ix_lean_training_weekly_tasks_status", "lean_training_weekly_tasks", ["status"]) op.create_table( "lean_training_completions", sa.Column("id", sa.Integer(), nullable=False), sa.Column("weekly_task_id", sa.Integer(), nullable=False), sa.Column("user_id", sa.Integer(), nullable=False), sa.Column("watched_at_json", sa.JSON(), nullable=True), sa.Column("summary_text", sa.Text(), nullable=True), sa.Column("summary_char_count", sa.Integer(), nullable=False), sa.Column("status", sa.String(length=20), nullable=False), sa.Column("completed_at", sa.DateTime(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["weekly_task_id"], ["lean_training_weekly_tasks.id"]), sa.ForeignKeyConstraint(["user_id"], ["users.id"]), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("weekly_task_id", "user_id", name="uq_lean_training_task_user"), ) op.create_index("ix_lean_training_completions_weekly_task_id", "lean_training_completions", ["weekly_task_id"]) op.create_index("ix_lean_training_completions_user_id", "lean_training_completions", ["user_id"]) op.create_index("ix_lean_training_completions_status", "lean_training_completions", ["status"]) op.create_index("ix_lean_training_completions_completed_at", "lean_training_completions", ["completed_at"]) op.create_table( "lean_training_reminders", sa.Column("id", sa.Integer(), nullable=False), sa.Column("weekly_task_id", sa.Integer(), nullable=False), sa.Column("recipient_user_id", sa.Integer(), nullable=False), sa.Column("event_key", sa.String(length=64), nullable=False), sa.Column("status", sa.String(length=20), nullable=False), sa.Column("trace_id", sa.String(length=64), nullable=True), sa.Column("error_message", sa.String(length=255), nullable=True), sa.Column("sent_at", sa.DateTime(), nullable=True), sa.Column("created_at", sa.DateTime(), nullable=False), sa.Column("updated_at", sa.DateTime(), nullable=False), sa.ForeignKeyConstraint(["weekly_task_id"], ["lean_training_weekly_tasks.id"]), sa.ForeignKeyConstraint(["recipient_user_id"], ["users.id"]), sa.PrimaryKeyConstraint("id"), sa.UniqueConstraint("weekly_task_id", "recipient_user_id", "event_key", name="uq_lean_training_reminder_event"), ) op.create_index("ix_lean_training_reminders_weekly_task_id", "lean_training_reminders", ["weekly_task_id"]) op.create_index("ix_lean_training_reminders_recipient_user_id", "lean_training_reminders", ["recipient_user_id"]) op.create_index("ix_lean_training_reminders_event_key", "lean_training_reminders", ["event_key"]) op.create_index("ix_lean_training_reminders_status", "lean_training_reminders", ["status"]) op.create_index("ix_lean_training_reminders_trace_id", "lean_training_reminders", ["trace_id"]) def downgrade() -> None: """删除精益培训新增表。""" op.drop_table("lean_training_reminders") op.drop_table("lean_training_completions") op.drop_table("lean_training_weekly_tasks")