chore(A10 W1): 收敛重复 bootstrap,db/migration 成平台表 DDL 单一真相

W1 引入 db/migration/V1-V3 后,平台表 DDL 在迁移与各模块 bootstrap-*.sql 重复
(评审揪出的"易漂移")。本次收敛,db/migration 成唯一真相:

- 删 3 份重复 bootstrap:bootstrap-page-schema(=V1)/bootstrap-datastatus(=V2)/
  bootstrap-ai-agent(=V3)。三者无运行态 classpath 消费者(已全仓核实)。
- AiAgentDdlTest(platform-ai,原读 bootstrap-ai-agent.sql)删除,等价覆盖迁入
  platform-app 新增 PlatformMigrationDdlGuardTest:① 守 V3 声明全部 AI 平台表/索引;
  ② 守 SchemaImportCli.CREATE_DDL ≡ V1(独立 CLI 兜底 DDL 防漂移)。
- SchemaImportCli.CREATE_DDL 由包私有改 public 供上述 guard 比对;两处过时注释改指 V1。
- ci.sh 平台表预灌改指 db/migration/V1(注:app 启动 Flyway 已幂等建表,此预灌仅冗余兜底)。
- docs 对齐:AI_AGENT_AUTO_DEVELOPMENT(spring.sql.init→Flyway)、docs/sql/SYS_PAGE_SCHEMA
  /SYS_AI_AGENT 头注释(待办→已落地)、A10 design 残留收敛标完成、deploy/README 残留项标完成。

边界:platform-parity 的 bootstrap-{sys,privilege,auth,xservice,multidim,flow}.sql 是
eip3 schema 对拍测试 fixture,非平台表副本,原样保留。

验证:全 reactor mvn clean install 绿;PlatformMigrationDdlGuardTest 2/2;独立 code-reviewer
评审 GO(零 CRITICAL/HIGH/MEDIUM,含 guard substring 逻辑对真实 V1 仿真核实)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-25 15:16:35 +08:00
parent b7fbae4cae
commit fa3c92b698
12 changed files with 94 additions and 228 deletions

View File

@@ -0,0 +1,67 @@
package com.eip4.platform.app;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.util.StreamUtils;
import com.eip4.platform.metadata.schema.SchemaImportCli;
/**
* A10 W1 收敛后:{@code db/migration} 是平台表 DDL 的【单一真相】(散落 bootstrap-*.sql 已删)。
* 本测试在【无 DB】下守两件防漂移契约,随每次构建跑(不依赖 PG):
* <ol>
* <li><b>V3 声明全部 AI Agent 平台表/索引</b>——取代原 platform-ai 的 {@code AiAgentDdlTest};
* 该模块已不再持有 {@code bootstrap-ai-agent.sql} 副本,DDL 单一真相归 V3。</li>
* <li><b>SchemaImportCli 内联建表 DDL ≡ V1</b>——独立 CLI 的自举兜底 DDL 是 sys_page_schema 的
* 另一处副本,删 bootstrap 后须钉死它与 V1 逐列一致,杜绝评审揪出的"易漂移"。</li>
* </ol>
* 真实 {@code flyway migrate} 行为另由 {@code FlywayMigrationLocalIT} 对真实 PG 验证(需 DB,assumeTrue 跳过)。
*/
class PlatformMigrationDdlGuardTest {
private String readMigration(String file) throws Exception {
try (InputStream in = getClass().getResourceAsStream("/db/migration/" + file)) {
assertNotNull(in, "缺少迁移文件: " + file);
return StreamUtils.copyToString(in, StandardCharsets.UTF_8);
}
}
/** 折叠空白 + 小写,做忽略格式的语义比对。 */
private static String norm(String s) {
return s.replaceAll("\\s+", " ").trim().toLowerCase();
}
@Test
@DisplayName("V3 迁移声明全部 AI Agent 平台表与索引(单一真相)")
void v3DeclaresAllAiAgentTables() throws Exception {
String ddl = readMigration("V3__sys_ai_agent.sql");
for (String table : new String[] {
"sys_ai_task", "sys_ai_draft", "sys_ai_change_set", "sys_ai_run",
"sys_ai_feature_package", "sys_ai_revision", "sys_ai_audit_log" }) {
assertTrue(ddl.contains("CREATE TABLE IF NOT EXISTS " + table), "V3 应声明表 " + table);
}
for (String idx : new String[] {
"idx_sys_ai_run_task", "idx_sys_ai_feature_package_task", "idx_sys_ai_revision_task" }) {
assertTrue(ddl.contains("CREATE INDEX IF NOT EXISTS " + idx), "V3 应声明索引 " + idx);
}
}
@Test
@DisplayName("SchemaImportCli 内联建表 DDL 与 V1 单一真相逐列一致(防漂移)")
void schemaImportCliDdlMatchesV1() throws Exception {
String v1 = readMigration("V1__sys_page_schema.sql");
int start = v1.indexOf("CREATE TABLE");
int end = v1.indexOf(");", start);
assertTrue(start >= 0 && end > start, "V1 应含 CREATE TABLE ... );");
String v1CreateTable = v1.substring(start, end + 1); // 含闭合 ")",不含 ";"
assertEquals(norm(SchemaImportCli.CREATE_DDL), norm(v1CreateTable),
"SchemaImportCli.CREATE_DDL 必须与 V1 建表语句逐列一致(单一真相 db/migration/V1)");
}
}