104 lines
4.2 KiB
Java
104 lines
4.2 KiB
Java
package scripts.qa;
|
|
|
|
import java.io.File;
|
|
import java.nio.file.Files;
|
|
import java.sql.*;
|
|
import java.util.*;
|
|
|
|
public class CheckRound1State {
|
|
private static final String TARGET_DB = "railwaysystem_integrated_qa_20260916";
|
|
|
|
public static void main(String[] args) {
|
|
String dbUrl = "jdbc:kingbase8://127.0.0.1:4321/" + TARGET_DB + "?useUnicode=true&characterEncoding=utf8¤tSchema=public,sys_catalog";
|
|
String user = "kingbase";
|
|
String password = resolveDbPassword();
|
|
|
|
try {
|
|
Class.forName("com.kingbase8.Driver");
|
|
try (Connection conn = DriverManager.getConnection(dbUrl, user, password)) {
|
|
// Identity Gate
|
|
String currentDb = null;
|
|
String currentUser = null;
|
|
String srvAddr = null;
|
|
String srvPort = null;
|
|
try (Statement st = conn.createStatement();
|
|
ResultSet rs = st.executeQuery("SELECT current_database(), current_user, inet_server_addr(), inet_server_port()")) {
|
|
if (rs.next()) {
|
|
currentDb = rs.getString(1);
|
|
currentUser = rs.getString(2);
|
|
srvAddr = rs.getString(3);
|
|
srvPort = rs.getString(4);
|
|
}
|
|
}
|
|
|
|
System.out.println("CURRENT_DATABASE: " + currentDb);
|
|
System.out.println("CURRENT_USER: " + currentUser);
|
|
System.out.println("SERVER_ADDR: " + srvAddr);
|
|
System.out.println("SERVER_PORT: " + srvPort);
|
|
|
|
if (!TARGET_DB.equals(currentDb)) {
|
|
System.err.println("FATAL: Connected to wrong database: " + currentDb + " (Expected: " + TARGET_DB + ")");
|
|
System.exit(1);
|
|
}
|
|
System.out.println("DB_ENVIRONMENT = ISOLATED_QA");
|
|
|
|
// Check core business tables
|
|
String[] coreTables = new String[]{
|
|
"train_student",
|
|
"train_teacher",
|
|
"train_course",
|
|
"train_class_plan",
|
|
"train_plan_course",
|
|
"train_enrollment",
|
|
"train_lesson",
|
|
"train_accommodation",
|
|
"train_dorm_auth",
|
|
"train_external_resource_mapping",
|
|
"train_external_operation",
|
|
"train_student_checkin",
|
|
"train_class_report"
|
|
};
|
|
|
|
System.out.println("\n--- ROUND 1 STATE VALIDATION (ROW COUNTS) ---");
|
|
boolean allEmpty = true;
|
|
for (String t : coreTables) {
|
|
try (Statement st = conn.createStatement();
|
|
ResultSet rs = st.executeQuery("SELECT count(*) FROM " + t)) {
|
|
if (rs.next()) {
|
|
int cnt = rs.getInt(1);
|
|
System.out.println(String.format("%-35s : %d", t, cnt));
|
|
if (cnt > 0) allEmpty = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (allEmpty) {
|
|
System.out.println("\nROUND 1 STATE VALIDATION: PASS (All core business tables empty)");
|
|
} else {
|
|
System.err.println("\nROUND 1 STATE VALIDATION: FAIL (Non-empty business tables found!)");
|
|
System.exit(1);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
System.exit(1);
|
|
}
|
|
}
|
|
|
|
private static String resolveDbPassword() {
|
|
String env = System.getenv("DB_PASSWORD");
|
|
if (env != null && !env.isEmpty()) return env;
|
|
try {
|
|
File yml = new File("RuoYi-Vue/ruoyi-admin/src/main/resources/application-druid.yml");
|
|
if (yml.exists()) {
|
|
for (String line : Files.readAllLines(yml.toPath())) {
|
|
if (line.trim().startsWith("password:")) {
|
|
return line.trim().substring("password:".length()).trim();
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception ignored) {}
|
|
return "123456";
|
|
}
|
|
}
|