fix(sql): make fee migration MySQL-compatible

This commit is contained in:
2026-08-10 15:52:40 +08:00
parent c9f1fe0093
commit 9ab7c01639
3 changed files with 82 additions and 30 deletions
@@ -0,0 +1,36 @@
package com.baiyue.firstleg.repository;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.assertj.core.api.Assertions.assertThat;
class FeeItemMigrationSqlContractTest {
@Test
void temporarySeedTableIsNotReopenedWithinOneMysqlStatement() throws Exception {
assertMysqlCompatible(resolve("deploy/sql/头程数据库统一增量-MySQL8.sql"));
assertMysqlCompatible(resolve(
"firstleg/src/main/resources/db/phase2-published-freight-detail-migration.sql"));
}
private static void assertMysqlCompatible(Path path) throws Exception {
String sql = Files.readString(path, StandardCharsets.UTF_8);
assertThat(sql)
.contains("LEFT JOIN tmp_fee_item_seed matched_seed")
.contains("matched_seed.fee_code = NULLIF(TRIM(f.fee_code), '')")
.contains("matched_seed.trade_scope = f.trade_scope")
.doesNotContain("LEFT JOIN tmp_fee_item_seed by_code")
.doesNotContain("LEFT JOIN tmp_fee_item_seed by_semantic")
.doesNotContain("OR (SELECT COUNT(*) FROM tmp_fee_item_seed")
.doesNotContain("OR EXISTS (SELECT trade_scope, fee_type_name FROM tmp_fee_item_seed");
}
private static Path resolve(String value) {
Path direct = Path.of(value);
if (Files.exists(direct)) return direct;
return Path.of("..", value).normalize();
}
}