Files
bid-doctor/server/migrations/sql/0001_baseline/03_project.sql
YANG JIANKUAN ad7fba6021 feat(server): 工程骨架后端——上传 → 解析 → 清单最小链路
- core:配置(prod 拒绝默认密钥 / dev 短信 / 假模型)、租户事务 + 行级安全策略、
  problem+json 错误码、信封加密与签名下载、对象存储、事务内入队、Valkey stream 事件流、权限点
- identity:手机号 HMAC 存储、注册、登录(挤下线需确认,API3)、服务端会话
- billing:额度流水只追加,预扣 / 结算 / 退回,一笔预扣只有一个结局
- document:分片上传、按文件头识别格式、Gotenberg 转换、文字层与稳定句子编号
- checklist:标注规则识别、模型抽取、三道校验、标注类条款规则兜底、重跑对齐
- ai:提示词注册表(extract.substantive v1 来自 S4 v2)、假模型、OpenAI 兼容供应商、ai_call 流水
- 迁移:data-model 基线、套餐、Procrastinate、会话状态函数
- 测试 30 个:租户隔离、额度、失败退回、对象加密、契约一致性
- Compose(含 migrate)、镜像、CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 18:48:10 +08:00

61 lines
3.3 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 3. project:项目、基本信息字段、分包、项目成员(FR-M2-03、04,FR-M6-01、02)
-- 来源:docs/architecture/schema-draft.sql(2026-11-03 验证过的草案)
CREATE TABLE project (
id uuid PRIMARY KEY,
tenant_id uuid NOT NULL REFERENCES tenant (id),
-- 下面几列是 project_field 的当前值,冗余在这里给工作台列表排序和筛选用
name text NOT NULL,
code text,
purchaser text,
agency text,
procurement_method text,
legal_regime text NOT NULL DEFAULT 'unknown'
CHECK (legal_regime IN ('gov_procurement', 'tendering', 'unknown')),
deadline_at timestamptz,
status text NOT NULL DEFAULT 'tracking'
CHECK (status IN ('tracking', 'drafting', 'checked', 'submitted', 'archived')),
status_before_archive text CHECK (status_before_archive IN ('checked', 'submitted')),
-- 就绪标记:只在 checked 状态显示(G7);由 check 模块在处理问题的同一个事务里更新
latest_check_run_id uuid,
open_fatal_count int NOT NULL DEFAULT 0,
last_charged_check_at timestamptz, -- 24 小时免扣的起点(P1)
created_by uuid NOT NULL REFERENCES user_account (id),
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (tenant_id, id)
);
CREATE INDEX ON project (tenant_id, status, deadline_at);
CREATE TABLE project_member ( -- AR12:MVP 只有建项目的人,角色 lead
tenant_id uuid NOT NULL,
project_id uuid NOT NULL,
user_id uuid NOT NULL REFERENCES user_account (id),
role text NOT NULL CHECK (role IN ('lead', 'editor', 'viewer')),
added_by uuid NOT NULL REFERENCES user_account (id),
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (tenant_id, project_id, user_id),
FOREIGN KEY (tenant_id, project_id) REFERENCES project (tenant_id, id) ON DELETE CASCADE
);
CREATE INDEX ON project_member (tenant_id, user_id);
CREATE TABLE lot ( -- 包 / 标段;没分包时只有一个默认包
id uuid PRIMARY KEY,
tenant_id uuid NOT NULL,
project_id uuid NOT NULL,
lot_no text NOT NULL, -- 原文里的写法:「1」「包2」「第三标段」
name text,
budget_amount numeric(18, 2),
ceiling_amount numeric(18, 2), -- 采购包限价;三层限价的另外两层见 data-model §5.3
is_default boolean NOT NULL DEFAULT false,
is_bidding boolean NOT NULL DEFAULT true, -- 用户选择投哪些包
origin text NOT NULL CHECK (origin IN ('ai', 'human')),
ai_values jsonb, -- AI 原值,人工修改不覆盖
edited_fields text[] NOT NULL DEFAULT '{}',
sort_order int NOT NULL DEFAULT 0,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (tenant_id, id),
UNIQUE (tenant_id, project_id, lot_no),
FOREIGN KEY (tenant_id, project_id) REFERENCES project (tenant_id, id) ON DELETE CASCADE
);