fix: 移除 site_configs 的 uk_site_version 唯一约束,版本号由服务端批准时自动分配
This commit is contained in:
@@ -70,7 +70,7 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
return sameHash;
|
||||
}
|
||||
|
||||
// 写入存储
|
||||
// 存储到抽象存储层
|
||||
try {
|
||||
storageService.store(storagePath, configJson);
|
||||
} catch (Exception e) {
|
||||
@@ -78,34 +78,12 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
throw new RuntimeException("存储配置文件失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
long fileSize = configJson.getBytes(StandardCharsets.UTF_8).length;
|
||||
|
||||
// 同一 (site_id, version) 已有 PENDING 记录 → 更新而非新增(避免唯一约束冲突)
|
||||
SiteConfig existingPending = siteConfigMapper.selectOne(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<SiteConfig>()
|
||||
.eq(SiteConfig::getSiteId, siteId)
|
||||
.eq(SiteConfig::getVersion, version)
|
||||
.eq(SiteConfig::getStatus, ConfigStatus.PENDING)
|
||||
.eq(SiteConfig::getDeleted, 0));
|
||||
if (existingPending != null) {
|
||||
// 删除旧存储文件
|
||||
storageService.delete(existingPending.getStoragePath());
|
||||
existingPending.setConfigHash(configHash);
|
||||
existingPending.setStoragePath(storagePath);
|
||||
existingPending.setFileSize(fileSize);
|
||||
existingPending.setSchemaVersion(schemaVersion != null ? schemaVersion : existingPending.getSchemaVersion());
|
||||
existingPending.setSubmitterId(submitterId);
|
||||
siteConfigMapper.updateById(existingPending);
|
||||
log.info("Config updated: siteId={}, version={}, id={}, hash={}", siteId, version, existingPending.getId(), configHash);
|
||||
return existingPending;
|
||||
}
|
||||
|
||||
SiteConfig config = new SiteConfig();
|
||||
config.setSiteId(siteId);
|
||||
config.setVersion(version);
|
||||
config.setVersion(version); // 客户端传入的版本,仅供参考;批准时会被自动分配的新版本号覆盖
|
||||
config.setConfigHash(configHash);
|
||||
config.setStoragePath(storagePath);
|
||||
config.setFileSize(fileSize);
|
||||
config.setFileSize((long) configJson.getBytes(StandardCharsets.UTF_8).length);
|
||||
config.setSchemaVersion(schemaVersion != null ? schemaVersion : "1.0.0");
|
||||
config.setStatus(ConfigStatus.PENDING);
|
||||
config.setSubmitterId(submitterId);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- PAR Flyway V11: 移除 site_configs 的 (site_id, version) 唯一约束
|
||||
-- 版本号在审批通过时才由服务端自动分配,提交时客户端传入的版本仅供参考,不应限制唯一
|
||||
ALTER TABLE site_configs DROP INDEX uk_site_version;
|
||||
Reference in New Issue
Block a user