liufumingren 43dae198db chore: Android 扫码台设置页、发布脚本健壮性与文档同步
- Android 扫码台:设置页新增「设为默认桌面 / 解除默认桌面 / 回到盒子桌面 / 打开系统设置」等现场免 adb 操作
- android_client/build.ps1:gradle 的 javac 提示走 stderr,改成 2>&1 逐行 Write-Host,避免被当成构建失败
- deploy-lib.cjs:ssh 加 ServerAliveInterval/CountMax 与 -n,避免发布脚本卡在远端命令结束前不退出
- set-password.js:重置密码时补写 password_changed_at(否则旧 JWT 不失效)
- .gitignore:忽略 video_split/(调试用的视频拆帧产物)
- 文档同步:README / backend README(微信网关、成员扫码绑定、平台管理员、顶栏下载入口、已下线的自建微信表)/
  database README / desktop README

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-10-29 17:21:41 +08:00

64 lines
4.9 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

# 数据库变更规范(DDL)
> **所有表结构变更只允许通过 sequelize-cli 迁移脚本执行,禁止直接连库改表。**
## 为什么
- 迁移记录在 `SequelizeMeta` 表里,换环境(开发 / 测试 / 生产)按同一条命令重放,不会漏表、漏字段;
- 直接 `ALTER TABLE` 无法回溯,环境之间会悄悄不一致;
- 回滚有据可依(每个迁移都有 `down`)。
## 目录与配置
```
backend/
├─ .sequelizerc # sequelize-cli 路径配置
├─ database/
│ ├─ config.cjs # 连接信息(与环境变量 / config.local.js 同源)
│ ├─ migrations/ # ★ DDL 脚本放这里
│ └─ seeders/ # 初始数据(可选)
```
连接信息由 `scripts/db-config.js` 统一解析:**环境变量 > `config/config.local.js` > 默认值**,
与运行时服务完全一致,避免「迁移改 A 库、服务连 B 库」。
## 常用命令
```bash
npm run db:migrate # 执行全部未执行的迁移
npm run db:migrate:status # 查看哪些执行过
npm run db:migrate:undo # 回滚最后一条
npm run db:migration:generate -- create_xxx_tables # 生成迁移骨架
```
## 写迁移的约定
- 表名/字段名用**下划线**,与既有表保持一致;
- 主键统一 `BIGINT UNSIGNED` 自增;
- 时间字段统一 `created_at` / `updated_at` / `deleted_at`(软删除),`status` 用 `TINYINT UNSIGNED`;
- 不建物理外键(与 `users`、`scanners` 等既有表一致),只建索引;
- `up()` 必须能重复执行前先看 `SequelizeMeta`(由 CLI 保证只跑一次),`down()` 必须能干净回滚。
## 已执行过的迁移
| 迁移 | 内容 |
|---|---|
| `20261018100000-create-nvr-camera-workstation-tables` | `nvrs` / `cameras` / `workstations` / `workstation_cameras` / `workstation_scan_channels` |
| `20261018150000-add-channel-name-to-cameras` | `cameras.channel_name`(设备通道名,与业务别名分开) |
| `20261018180000-add-has-ptz-to-cameras` | `cameras.has_ptz`(是否支持云台) |
| `20261018200000-add-workstation-layout` | `workstations.canvas_width/height` + `workstation_cameras.x/y/width/height/stream_type/z_index` |
| `20261018200100-backfill-workstation-camera-layout` | 回填已有绑定关系的画布位置(第 1 条铺满 / 第 2 条右上 / 其余左下) |
| `20261018210000-add-workstation-type` | `workstations.ws_type`(1 散单 / 2 团购) |
| `20261018220000-add-workstation-record-range` | `workstations.record_before_sec/record_after_sec/record_max_sec`(录制范围与最大录制时长) |
| `20261018230000-create-subject-tables` | 新表 `subjects` / `subject_members`;`scanners`/`nvrs`/`cameras`/`workstations`/`scan_channels`/`scan_records` 加 `subject_id`,并把已有数据回填到「每人一个主体」 || `20261019233000-drop-has-ptz-from-cameras` | 删除 `cameras.has_ptz`(预览统一显示云台面板,后端不再标记是否支持云台) |
| `20261024100000-add-workstation-login-fields` | `workstations.login_code`(登录码 `WSC-` 前缀,唯一)/ `last_active_at`(最后活跃时间)/ `idle_timeout_sec`(多少秒不活跃自动下线,团购 3600 / 散单 1800),并回填已有工作台(⚠️ `login_code` 已被 `20261028121000` 删除) |
| `20261024101000-create-workstation-login-records` | 新表 `workstation_login_records`(工作台成员登录记录,含 `(workstation_id, login_at)` 等索引) |
| `20261024102000-add-workstation-camera-label-flag` | `workstation_cameras.is_label_camera`(面单摄像头标记,仅散单工作台;一台工作台最多一路) |
| `20261028120000-create-wechat-gateway-bindings` | 新表 `wechat_gateway_bindings`(微信登录网关绑定:`user_id` / `app_key` / `openid`(唯一)/ `unionid` / `bind_scene` / `last_login_at`) |
| `20261028121500-add-subject-member-temp-user` | `subject_members.temp_user_id`(扫码绑定时自动建给成员的临时账号;被已有账号继承时该账号会被删除) |
| `20261028121000-drop-workstation-login-code` | 删除 `workstations.login_code`(`WSC-` 登录码已废弃,扫码登入改走微信登录网关的一次性二维码);`workstation_login_records.login_code` 保留作历史 |
| `20261029100000-drop-legacy-wechat-tables` | 删除 `wechat_oauth`(自建公众号网页授权)与 `wechat_mp_accounts`(小程序 code2Session 一键登录):微信侧接入已统一走登录网关;`down` 按原结构重建两张空表 |
| `20261029120000-create-admin-members` | 新表 `admin_members`(平台管理员:`user_id` 唯一、`name`、`role`、`status`、`remark`)+ 把内置管理员(`username='admin'`,没有就 `id=1`)先入表 |
> 历史遗留的 `sql/schema.sql` + `sql/migrations/*.sql`(用 `npm run db:init` 执行)是接入 sequelize-cli 之前的做法,
> 只用于初始化老表;**新变更一律写 `database/migrations/*.js`**。