1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 
/** 只读:看测试库的 merchant 表到底有没有那两个列,以及 Flyway 记到哪一版。 */
public class TestSchemaProbe {
    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://127.0.0.1:8134/talent_card_test?useUnicode=true&characterEncoding=utf8"
                + "&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&useSSL=false";
        Path out = Path.of(".scratch/payment-409-probe/out3.txt");
        StringBuilder text = new StringBuilder();
        Class.forName("com.mysql.cj.jdbc.Driver");
        try (Connection c = DriverManager.getConnection(url, "root", "123456")) {
            text.append("--- merchant 上的相关列 ---\n");
            dump(text, c, "select column_name from information_schema.columns where table_schema=database() and table_name='merchant' and column_name in ('merchant_rights_config','merchant_type_code','business_address')");
            text.append("--- flyway 版本(最近 8 条)---\n");
            dump(text, c, "select version, description, success from flyway_schema_history order by installed_rank desc limit 8");
            text.append("--- merchant_onboarding_application.business_address 是否存在 ---\n");
            dump(text, c, "select column_name, column_type from information_schema.columns where table_schema=database() and table_name='merchant_onboarding_application' and column_name='business_address'");
        }
        System.out.println(text);
        Files.writeString(out, text.toString(), StandardCharsets.UTF_8);
    }
 
    private static void dump(StringBuilder text, Connection c, String sql) {
        try (Statement s = c.createStatement(); ResultSet rs = s.executeQuery(sql)) {
            int n = 0;
            while (rs.next()) { n++; StringBuilder row = new StringBuilder();
                for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++) row.append(rs.getString(i)).append("  ");
                text.append(row).append('\n'); }
            if (n == 0) text.append("(空)\n");
        } catch (Exception e) { text.append("查询失败:").append(e.getMessage()).append('\n'); }
    }
}