yeg
2026-09-14 910018aa5ac2dfe1e9c9cfc17051e40e4979b4c1
chore(test): 禁止重置开发库,并写清开发库与测试库的区别

开发库 talent_card 里有一批迁移从未创建的历史表(手建),reset-test-db.ps1 删表会连数据一起丢,且 flyway 在该库关闭、无法重建。脚本改为直接拒绝该库,docs/agents/testing.md 补一节说明正确的补结构/回灌方式。
2个文件已修改
25 ■■■■■ 已修改文件
docs/agents/testing.md 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
talent-card-server/scripts/reset-test-db.ps1 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/agents/testing.md
@@ -36,6 +36,22 @@
  且曾观察到卡死)。测试 profile 已关闭该导入,所以上面的重置脚本不会再有这个代价。
- 手工删 history 行会让已执行的 DDL 与 Flyway 记录不一致,后续迁移报错更难查。
## 不要重建开发库
`127.0.0.1:8134/talent_card` 是**开发库**(后台管理页和两个小程序都连它),不是测试库。它里面有
一批**迁移从未创建**的表——当年是直接在库里手建的,例如 `dependent_card_apply`、`merchant_benefit_rule`。
所以「把测试库结构克隆到开发库」「`reset-test-db.ps1 -Database talent_card`」这类操作会把开发库里这些
表连同数据一起删掉:2026-09-13 就这样丢过一批,最后靠 `127.0.0.1:6134/talent_card` 上的同源快照才回灌回来。
注意开发库的 `spring.flyway.enabled=false`:它**不会**被迁移自动修正,缺表只能手工补。
需要让开发库结构跟上迁移时:
- 只补缺失的 DDL(`create table if not exists`),**不要**删表重建;
- 动结构之前先 dump:`docker exec talent-card-mysql-1 mysqldump -uroot -p123456 talent_card > backup.sql`;
- 从旧快照回灌数据用 `.scratch/automatic-withdrawal/tools/RestoreOldData.java`(按列交集 `INSERT IGNORE`,
  只新增不删改)。该 MySQL 开了 binlog 且保留 30 天,误删后还能查证与补救。
## 迁移是只追加的
已经执行过的 `V*__*.sql` **不要改**(改一个字符就会 checksum 不匹配,测试库直接起不来)。需要调整
talent-card-server/scripts/reset-test-db.ps1
@@ -10,7 +10,10 @@
# Usage:
#   .\scripts\reset-test-db.ps1
#   .\scripts\reset-test-db.ps1 -Database talent_card_test -Port 8134 -User root -Password 123456
#   .\scripts\reset-test-db.ps1 -Database talent_card            # reset another schema on the same server
#
# The dev schema (talent_card) is refused on purpose: it holds tables that no migration creates
# (hand-made in the shared dev database), so dropping them loses data that cannot be rebuilt from
# db/migration. See "不要重建开发库" in docs/agents/testing.md.
param(
    [string] $Database = '',
    [string] $DatabaseHost = '',
@@ -84,6 +87,10 @@
if (-not $User)       { $User = if ($env:TEST_DATASOURCE_USERNAME) { $env:TEST_DATASOURCE_USERNAME } else { 'root' } }
if (-not $Password)   { $Password = if ($env:TEST_DATASOURCE_PASSWORD) { $env:TEST_DATASOURCE_PASSWORD } else { '123456' } }
if ($Database -eq 'talent_card') {
    throw "拒绝重置开发库 talent_card:它含有迁移从未创建的历史表(如 dependent_card_apply、merchant_benefit_rule),删表会丢数据且无法从 db/migration 重建。详见 docs/agents/testing.md。"
}
$driver = Find-MySqlDriver
if (-not $driver) {
    throw 'mysql-connector-j was not found in the Maven local repository. Run ".\mvnw.cmd -o test-compile" once so Maven downloads the project dependencies.'