Files
Neo-ZQYY/docs/prd/specs/P1-miniapp-db-foundation.md

64 lines
2.2 KiB
Markdown
Raw Permalink 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.
# P1基础设施层 — miniapp-db-foundation
> 优先级P1最高无前置依赖
> 预估工作量:中等
---
## 需求Requirements
### 用户故事
1. 作为后端开发者,我需要 `test_zqyy_app` 中有清晰的 Schema 划分(`auth` + `biz`),以便按功能组织业务表。
2. 作为后端开发者,我需要通过 FDW 从 `test_zqyy_app` 读取 ETL 库的 DWS/DWD 数据,以便小程序页面展示 ETL 计算结果。
3. 作为系统管理员,我需要 RLS 视图按 `site_id` 隔离数据,以便多门店数据安全。
### 验收标准
- AC1`test_zqyy_app` 中存在 `auth``biz` 两个 Schema权限配置正确
- AC2`test_etl_feiqiu.app` Schema 中为数据依赖矩阵列出的所有表创建了 RLS 视图
- AC3`test_zqyy_app.fdw_etl` 中所有外部表可正常 `SELECT`,数据与源表一致
- AC4RLS 视图在设置 `app.current_site_id` 后正确过滤数据
- AC5所有变更有对应的迁移脚本`db/zqyy_app/migrations/` + `db/etl_feiqiu/migrations/`
---
## 设计要点
### Schema 规划
```
test_zqyy_app
├── auth — 用户认证、权限、映射
├── biz — 业务数据任务、备注、AI、Excel
├── fdw_etl — FDW 外部表(只读,映射 ETL app schema
└── public — 保留现有系统管理表admin_users 等)
```
### RLS 实现方案
```sql
-- ETL 库 app schema 示例
CREATE VIEW app.v_dws_member_consumption_summary AS
SELECT * FROM dws.dws_member_consumption_summary
WHERE site_id = current_setting('app.current_site_id')::bigint;
```
### FDW 映射
- 使用 `postgres_fdw` 扩展
- 外部服务器指向 `test_etl_feiqiu`
- 外部表映射 `app` schema 的 RLS 视图(而非直接映射 dws/dwd 表)
- 映射表清单见 `00-数据依赖矩阵.md` 第四节
---
## 任务清单
- [ ] T1创建 `auth``biz` Schema + 权限配置
- [ ] T2`test_etl_feiqiu.app` 中创建全部 RLS 视图(约 33 张)
- [ ] T3配置 `postgres_fdw` 外部服务器和用户映射
- [ ] T4`fdw_etl` 中创建全部外部表
- [ ] T5编写验证脚本检查所有外部表可查询
- [ ] T6编写迁移脚本并归档