fix: make unified database migrations converge
This commit is contained in:
@@ -9,6 +9,21 @@ import java.nio.file.Path;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class FinanceWalletContractTest {
|
||||
@Test
|
||||
void unifiedMigrationDropsTheLegacyBalanceConstraintBeforeRewritingBalances() throws Exception {
|
||||
Path migration = Path.of("deploy/sql/头程数据库统一增量-MySQL8.sql");
|
||||
if (!Files.exists(migration)) migration = Path.of("..").resolve(migration);
|
||||
String sql = Files.readString(migration, StandardCharsets.UTF_8);
|
||||
int procedure = sql.indexOf("CREATE PROCEDURE migrate_fin_wallet_credit()");
|
||||
int dropConstraint = sql.indexOf("ALTER TABLE fin_wallet_account DROP CHECK chk_fin_wallet_account_balance", procedure);
|
||||
int rewriteBalance = sql.indexOf("SET actual_balance=actual_balance-credit_used", procedure);
|
||||
|
||||
assertThat(procedure).isGreaterThanOrEqualTo(0);
|
||||
assertThat(sql.substring(procedure, rewriteBalance))
|
||||
.contains("CHECK_CLAUSE LIKE '%actual_balance%'", "v_legacy_wallet_constraint OR v_credit_expiry_missing");
|
||||
assertThat(dropConstraint).isBetween(procedure, rewriteBalance - 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void schemaKeepsBalancesConsistentAndRechargeReviewTraceable() throws Exception {
|
||||
String sql = Files.readString(Path.of("src/main/resources/db/finance.sql"), StandardCharsets.UTF_8);
|
||||
|
||||
Reference in New Issue
Block a user