-- 032_worker_work_order_views.sql —— 打手个人工单首次查看状态。

CREATE TABLE IF NOT EXISTS worker_work_order_views (
  work_order_id BIGINT NOT NULL REFERENCES work_orders(id) ON DELETE CASCADE,
  worker_id BIGINT NOT NULL REFERENCES worker_users(id) ON DELETE CASCADE,
  viewed_at TIMESTAMPTZ NOT NULL,
  PRIMARY KEY (work_order_id, worker_id)
);

CREATE INDEX IF NOT EXISTS idx_worker_work_order_views_worker_order
  ON worker_work_order_views(worker_id, work_order_id);

COMMENT ON TABLE worker_work_order_views IS '打手个人工单首次查看记录，用于展示未读“新”标识';
COMMENT ON COLUMN worker_work_order_views.viewed_at IS '首次点击订单详情、复制资料、编辑备注或验收时写入';
