优化
This commit is contained in:
+35
-5
@@ -26,10 +26,13 @@ class SchemaChineseCommentContractTest {
|
||||
Path.of("src", "main", "resources", "db", "lastleg.sql"), StandardCharsets.UTF_8);
|
||||
String incremental = Files.readString(
|
||||
Path.of("..", "scripts", "db", "incremental.sql"), StandardCharsets.UTF_8);
|
||||
String overseasUnified = Files.readString(
|
||||
Path.of("..", "deploy", "sql", "海外区域统一增量-MySQL8.sql"), StandardCharsets.UTF_8);
|
||||
|
||||
List<TableDefinition> baselineTables = assertAllChineseComments(baseline, "基线 SQL", 55);
|
||||
assertAllChineseComments(incremental, "增量 SQL", 49);
|
||||
assertCommentMigrationCovers(incremental, baselineTables);
|
||||
assertAllChineseComments(overseasUnified, "海外统一增量 SQL", 10);
|
||||
assertCommentMigrationCovers(incremental, overseasUnified, baselineTables);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,21 +81,48 @@ class SchemaChineseCommentContractTest {
|
||||
return tables;
|
||||
}
|
||||
|
||||
private static void assertCommentMigrationCovers(String incremental, List<TableDefinition> tables) {
|
||||
private static void assertCommentMigrationCovers(
|
||||
String incremental,
|
||||
String overseasUnified,
|
||||
List<TableDefinition> tables
|
||||
) {
|
||||
int marker = incremental.indexOf("2026-08-18 / 025 Chinese table and column comments");
|
||||
assertTrue(marker >= 0, "增量 SQL 缺少 025 中文备注迁移");
|
||||
String migration = incremental.substring(marker);
|
||||
for (TableDefinition table : tables) {
|
||||
assertTrue(migration.contains("table_name='" + table.name() + "'"),
|
||||
boolean createdInLegacy = hasCommentedCreate(migration, table.name());
|
||||
boolean createdInUnified = hasCommentedCreate(overseasUnified, table.name());
|
||||
assertTrue(createdInLegacy || createdInUnified
|
||||
|| migration.contains("table_name='" + table.name() + "'"),
|
||||
"025 备注迁移缺少表: " + table.name());
|
||||
if (createdInLegacy || createdInUnified) {
|
||||
continue;
|
||||
}
|
||||
for (String column : table.columns()) {
|
||||
assertTrue(migration.contains("table_name='" + table.name()
|
||||
+ "' AND column_name='" + column + "'"),
|
||||
boolean repaired = migration.contains("table_name='" + table.name()
|
||||
+ "' AND column_name='" + column + "'");
|
||||
boolean addedWithComment = hasCommentedAdd(migration, column)
|
||||
|| hasCommentedAdd(overseasUnified, column);
|
||||
assertTrue(repaired || addedWithComment,
|
||||
"025 备注迁移缺少字段: " + table.name() + "." + column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasCommentedCreate(String sql, String table) {
|
||||
return Pattern.compile(
|
||||
"(?is)CREATE\\s+TABLE\\s+IF\\s+NOT\\s+EXISTS\\s+" + Pattern.quote(table)
|
||||
+ "\\s*\\(.*?\\)\\s*ENGINE\\s*=\\s*InnoDB\\s+COMMENT\\s*=\\s*'[^']*[\\u4e00-\\u9fff][^']*'\\s*;")
|
||||
.matcher(sql).find();
|
||||
}
|
||||
|
||||
private static boolean hasCommentedAdd(String sql, String column) {
|
||||
return Pattern.compile(
|
||||
"(?is)ADD\\s+COLUMN\\s+" + Pattern.quote(column)
|
||||
+ "\\b[^;]*?COMMENT\\s+''?[^;]*[\\u4e00-\\u9fff][^;]*''?")
|
||||
.matcher(sql).find();
|
||||
}
|
||||
|
||||
private static boolean isConstraint(String definition) {
|
||||
String normalized = definition.stripLeading().toUpperCase();
|
||||
return normalized.startsWith("PRIMARY ") || normalized.startsWith("UNIQUE ")
|
||||
|
||||
Reference in New Issue
Block a user