unis-oa/sql/upgrade/20261116_read_forwarded.sql

38 lines
2.9 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- 2026-11-16 生产库结构增量:待阅/已阅要能分辨「环节配的抄送」与「发起人事后手工转发」
--
-- 症状:镜像升到 202611161652 之后,打开待办/任务详情页报 500,日志里整屏
-- (1054, "Unknown column 'oa_read.forwarded' in 'field list'"),栈落在
-- backend/app/api/runtime.py 的 get_job → _job_response → parallel.gather。
-- 服务照起、健康检查照过,坏的是碰到 oa_read / oa_read_completed 的那几只接口
-- (详情页、待阅列表、批量登记已阅、轨迹图上那份抄送账)。
-- 原因:这一版新增「办结之后的转发」——POST /api/v1/work/{id}/forward,发起人在单子
-- 办结之后手工把它递给某人。转发在待阅里与抄送是同一种东西(read_type 照旧写
-- 'cc':待阅列表、筛选、导出认的是 cc / share / comment 那三种),但轨迹图不能
-- 把一次转发念成一次抄送,所以要一个布尔把它单独标出来。老数据全是 0,等于
-- 「没被转发过」,正是它从前应有的样子,不迁数据。
-- 范围:oa_read 与 oa_read_completed 各加一列 forwarded(tinyint(1) NOT NULL DEFAULT 0)。
-- 口径见 backend/app/engine/engine.py 的 forward_completed 与 _refresh_read:
-- 再抄 / 再转命中同一条时取并集(被抄过又被转发过的人两种都算);登记已阅时整行
-- 搬进 oa_read_completed(mark_read),办结搬档那一条也一样带过来。归档之后回看
-- 「这单被转发给过谁」全靠归档表上这一列。
-- 执行:DBA 在生产库上跑下面两句。重复跑会在同一句报 1060 Duplicate column name,
-- 是预期噪音。应用启动时的建表补列体检(ensure_columns)也会自己补这两列,
-- 跑不跑都行;先跑可以让升级窗口里的老进程照样读到默认值而不是缺列。
-- ⚠️ 顺序上必须在上新后端之前跑完:生产档 auto_create_schema=false 启动不补列,
-- 先上后端就是上面那条 1054。反过来先跑 SQL,老进程根本不读这一列,一个字不影响。
-- 两张表都是小表(生产 17 行 / 23 行),MySQL 8 走 instant DDL,不锁表。
-- 之后:不用回填,不用重启。新转发由引擎当场写 1;界面上的入口在单据详情页的「转发」,
-- 读数在 frontend/src/utils/flowForwards.ts 与 flowCc.ts 那两份说法里。
ALTER TABLE `oa_read` ADD COLUMN `forwarded` tinyint(1) NOT NULL DEFAULT '0';
ALTER TABLE `oa_read_completed` ADD COLUMN `forwarded` tinyint(1) NOT NULL DEFAULT '0';
-- 核账:两列都在,且存量行全部落成 0(没被转发过)
SELECT COUNT(*) AS reads_total,
SUM(`forwarded` = 1) AS reads_forwarded
FROM `oa_read`;
SELECT COUNT(*) AS archived_reads_total,
SUM(`forwarded` = 1) AS archived_reads_forwarded
FROM `oa_read_completed`;