ApplyLobsterSemanticMenuRename.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import java.nio.charset.StandardCharsets;
  2. import java.nio.file.Files;
  3. import java.nio.file.Path;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8. /** Apply V20260729: menu_id=29933 锟解户锟斤拷锟斤拷丶锟斤拷锟?锟斤拷 锟斤拷锟斤拷丶锟斤拷锟?*/
  9. public class ApplyLobsterSemanticMenuRename {
  10. private static final String HOST = "cq-cdb-8fjmemkb.sql.tencentcdb.com:27220";
  11. private static final String USER = "root";
  12. private static final String PASS = "Ylrz_1q2w3e4r5t6y";
  13. public static void main(String[] args) throws Exception {
  14. Class.forName("com.mysql.cj.jdbc.Driver");
  15. String tenantDb = args.length > 0 ? args[0] : "fs_tenant_cs1";
  16. String tenantSql = read("d:/ylrz_saas_new/java/fs-agent/src/main/resources/db/migration/tenant/V20260729_01__lobster_semantic_menu_rename.sql");
  17. String masterSql = read("d:/ylrz_saas_new/java/fs-agent/src/main/resources/db/migration/master/V20260729_01__lobster_semantic_menu_rename_master.sql");
  18. System.out.println("=== MASTER ylrz_saas ===");
  19. try (Connection c = open("ylrz_saas")) {
  20. exec(c, masterSql);
  21. show(c, "tenant_sys_menu");
  22. }
  23. System.out.println("\n=== TENANT " + tenantDb + " ===");
  24. try (Connection c = open(tenantDb)) {
  25. exec(c, tenantSql);
  26. show(c, "sys_menu");
  27. }
  28. System.out.println("\nDone.");
  29. }
  30. private static String read(String path) throws Exception {
  31. byte[] bytes = Files.readAllBytes(Path.of(path));
  32. String s = new String(bytes, StandardCharsets.UTF_8);
  33. return s.startsWith("\uFEFF") ? s.substring(1) : s;
  34. }
  35. private static void exec(Connection c, String sql) throws Exception {
  36. try (Statement st = c.createStatement()) {
  37. st.execute(sql);
  38. }
  39. }
  40. private static void show(Connection c, String table) throws Exception {
  41. String sql = "SELECT menu_id, menu_name, HEX(menu_name) hx FROM " + table + " WHERE menu_id = 29933";
  42. try (Statement st = c.createStatement(); ResultSet rs = st.executeQuery(sql)) {
  43. if (rs.next()) {
  44. System.out.println(rs.getLong(1) + " | " + rs.getString(2) + " | hx=" + rs.getString(3));
  45. } else {
  46. System.out.println("menu_id=29933 not found in " + table);
  47. }
  48. }
  49. }
  50. private static Connection open(String db) throws Exception {
  51. return DriverManager.getConnection(
  52. "jdbc:mysql://" + HOST + "/" + db + "?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&allowMultiQueries=true",
  53. USER, PASS);
  54. }
  55. }