fix: keep ambiguous legacy phones unbound
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
package com.baiyue.auth.repository;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class AuthLoginIdentifiersSqlContractTest {
|
||||
@Test
|
||||
void backfillsOnlyUniquelyOwnedPhonesAndKeepsDuplicateLegacyPhonesUnbound() throws Exception {
|
||||
assertSafeBackfill(new ClassPathResource("db/auth-login-identifiers.sql")
|
||||
.getContentAsString(StandardCharsets.UTF_8));
|
||||
assertSafeBackfill(Files.readString(unifiedSql(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private static void assertSafeBackfill(String sql) {
|
||||
assertThat(sql)
|
||||
.contains("phone NOT REGEXP '^1[3-9][0-9]{9}$'")
|
||||
.contains("HAVING COUNT(DISTINCT auth_user_id) = 1")
|
||||
.contains("ADD UNIQUE KEY uk_auth_account_phone (phone)")
|
||||
.doesNotContain("IAM 存在重复手机号,禁止建立 Auth 唯一登录索引");
|
||||
}
|
||||
|
||||
private static Path unifiedSql() {
|
||||
Path path = Path.of("deploy", "sql", "头程数据库统一增量-MySQL8.sql");
|
||||
return Files.exists(path) ? path : Path.of("..", "deploy", "sql", "头程数据库统一增量-MySQL8.sql");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user