import com.fasterxml.jackson.databind.ObjectMapper; import java.nio.file.*; import java.sql.*; import java.util.*; /** Deployment readiness only: no DDL/DML and no automatic initialization. */ public class ReadOnlyProductionPreflight { public static void main(String[] args) throws Exception { Map config = new HashMap<>(); boolean master = false; for (String line : Files.readAllLines(Path.of("ruoyi-admin/src/main/resources/application-druid.yml"))) { if (line.trim().equals("master:")) { master=true; continue; } if (line.trim().equals("slave:")) break; if (master && line.indexOf(':') > 0) { int colon=line.indexOf(':'); config.put(line.substring(0,colon).trim(),DatabaseTool.value(line.substring(colon+1).trim())); } } String configured=config.get("url"); if (configured==null || !configured.matches("^jdbc:mysql://192\\.168\\.28\\.10:3306/cmvr-project-dev(?:\\?.*)?$")) throw new IllegalStateException("Unexpected local datasource"); var properties=new Properties();properties.setProperty("user",config.get("username"));properties.setProperty("password",config.get("password"));properties.setProperty("connectTimeout","5000");properties.setProperty("socketTimeout","60000"); var report=new LinkedHashMap();report.put("database","cmvr-project-prod");report.put("readOnly",true); try(var c=DriverManager.getConnection(configured.replace("/cmvr-project-dev","/cmvr-project-prod"),properties)) { c.setReadOnly(true);c.setAutoCommit(false);try(var s=c.createStatement()){s.execute("START TRANSACTION READ ONLY");} try(var s=c.createStatement();var r=s.executeQuery("select database()")){r.next();if(!"cmvr-project-prod".equals(r.getString(1)))throw new IllegalStateException("Production target mismatch");} var tables=new TreeMap(); try(var s=c.prepareStatement("select table_name from information_schema.tables where table_schema=? and table_type='BASE TABLE'")){s.setString(1,"cmvr-project-prod");try(var r=s.executeQuery()){while(r.next())tables.put(r.getString(1),0L);}} for(String name:tables.keySet()){if(!name.matches("[A-Za-z0-9_]+"))throw new IllegalStateException("Unexpected identifier");try(var s=c.createStatement();var r=s.executeQuery("select count(*) from `"+name+"`")){r.next();tables.put(name,r.getLong(1));}} var missing=new ArrayList(); try(var s=c.prepareStatement("select d.table_name,d.column_name from information_schema.columns d left join information_schema.columns p on p.table_schema='cmvr-project-prod' and p.table_name=d.table_name and p.column_name=d.column_name where d.table_schema='cmvr-project-dev' and p.column_name is null order by d.table_name,d.ordinal_position");var r=s.executeQuery()){while(r.next())missing.add(r.getString(1)+"."+r.getString(2));} report.put("tableCounts",tables);report.put("missingColumnsComparedWithDevelopment",missing);c.rollback(); } Path output=Path.of(".codex-tmp/deploy-production/preflight.json");Files.createDirectories(output.getParent());Files.writeString(output,new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(report)); System.out.println("Read-only production preflight saved: "+output); System.out.println("Production tables: "+((Map)report.get("tableCounts")).size()+"; missing columns: "+((List)report.get("missingColumnsComparedWithDevelopment")).size()); } }