From 262c91765c586dc1c6da7ea2e0d7f122ebe0a116 Mon Sep 17 00:00:00 2001 From: shenzhidan Date: Mon, 13 Jul 2026 17:12:57 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/FlywayRecoveryConfiguration.java | 55 +++++++++++++++++++ start/src/main/resources/nacos-prod.yml | 4 +- start/src/main/resources/nacos.yml | 4 +- .../src/main/resources/nacos/config-mysql.yml | 4 +- .../src/main/resources/TableCreationDDL.sql | 4 +- 5 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 start/src/main/java/com/zcloud/personnel/positioning/config/FlywayRecoveryConfiguration.java diff --git a/start/src/main/java/com/zcloud/personnel/positioning/config/FlywayRecoveryConfiguration.java b/start/src/main/java/com/zcloud/personnel/positioning/config/FlywayRecoveryConfiguration.java new file mode 100644 index 0000000..6d55cf1 --- /dev/null +++ b/start/src/main/java/com/zcloud/personnel/positioning/config/FlywayRecoveryConfiguration.java @@ -0,0 +1,55 @@ +package com.zcloud.personnel.positioning.config; + +import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.flyway.FlywayMigrationStrategy; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Recovers the known partial MySQL migration left by V20260710_02. + * + *

The migration is idempotent and can be safely rerun after Flyway removes + * its failed history entry. Other failed migrations are never repaired + * automatically so that new database problems still stop application startup.

+ */ +@Configuration +public class FlywayRecoveryConfiguration { + + private static final Logger LOGGER = LoggerFactory.getLogger(FlywayRecoveryConfiguration.class); + private static final MigrationVersion RECOVERABLE_VERSION = MigrationVersion.fromVersion("20260710.02"); + + @Bean + public FlywayMigrationStrategy flywayMigrationStrategy() { + return flyway -> { + List failedMigrations = Arrays.stream(flyway.info().all()) + .filter(migration -> migration.getState().isFailed()) + .collect(Collectors.toList()); + + if (!failedMigrations.isEmpty()) { + boolean onlyKnownFailure = failedMigrations.size() == 1 + && RECOVERABLE_VERSION.equals(failedMigrations.get(0).getVersion()); + if (!onlyKnownFailure) { + String failedVersions = failedMigrations.stream() + .map(migration -> migration.getVersion() == null + ? migration.getDescription() + : migration.getVersion().toString()) + .collect(Collectors.joining(", ")); + throw new IllegalStateException( + "Flyway contains unsupported failed migrations: " + failedVersions); + } + + LOGGER.warn("Repairing known failed Flyway migration {} before retry", RECOVERABLE_VERSION); + flyway.repair(); + } + + flyway.migrate(); + }; + } +} diff --git a/start/src/main/resources/nacos-prod.yml b/start/src/main/resources/nacos-prod.yml index a6b4ba0..f243e7f 100644 --- a/start/src/main/resources/nacos-prod.yml +++ b/start/src/main/resources/nacos-prod.yml @@ -2,9 +2,9 @@ nacos: url: prod-nacos:8848 namespace: jjb-dragon application: - name: zcloud-gbs-personnel-positioning + name: zcloud-gbs-personnel-position version: - gateway: personnelPositioning + gateway: personnelPosition cn-name: 人员定位 spring: application: diff --git a/start/src/main/resources/nacos.yml b/start/src/main/resources/nacos.yml index 1ee6005..8cc37fb 100644 --- a/start/src/main/resources/nacos.yml +++ b/start/src/main/resources/nacos.yml @@ -2,9 +2,9 @@ nacos: url: 192.168.20.100:30290 namespace: jjb-dragon application: - name: zcloud-gbs-personnel-positioning + name: zcloud-gbs-personnel-position version: - gateway: personnelPositioning + gateway: personnelPosition cn-name: 人员定位 spring: application: diff --git a/start/src/main/resources/nacos/config-mysql.yml b/start/src/main/resources/nacos/config-mysql.yml index 4365a53..58734ea 100644 --- a/start/src/main/resources/nacos/config-mysql.yml +++ b/start/src/main/resources/nacos/config-mysql.yml @@ -1,5 +1,5 @@ mysql: - db: ${spring.application.name} + db: zcloud-gbs-personnel-position spring: shardingsphere: druid: @@ -76,4 +76,4 @@ spring: # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 wall: - multi-statement-allow: true \ No newline at end of file + multi-statement-allow: true diff --git a/web-infrastructure/src/main/resources/TableCreationDDL.sql b/web-infrastructure/src/main/resources/TableCreationDDL.sql index 581bf40..01181d3 100644 --- a/web-infrastructure/src/main/resources/TableCreationDDL.sql +++ b/web-infrastructure/src/main/resources/TableCreationDDL.sql @@ -1,7 +1,7 @@ -CREATE DATABASE IF NOT EXISTS `zcloud-gbs-personnel-positioning` +CREATE DATABASE IF NOT EXISTS `zcloud-gbs-personnel-position` DEFAULT CHARACTER SET utf8mb4; -USE `zcloud-gbs-personnel-positioning`; +USE `zcloud-gbs-personnel-position`; -- 实时位置、轨迹点不落 MySQL;页面实时查询直接走 FindS,必要时使用 Redis 短缓存。 -- MySQL 只保存 GBS 侧业务配置、三方映射、告警闭环和同步审计。