версия БД
This commit is contained in:
parent
2a58d73e52
commit
04601b618b
7 changed files with 93 additions and 1 deletions
|
|
@ -69,6 +69,8 @@ ct.monitoring-interval=${MONITORING_INTERVAL:15}
|
|||
ct.update-flags-interval=${UPDATE_FLAGS_INTERVAL:1}
|
||||
ct.days-to-update-flags=${DAYS_TO_UPDATE_FLAGS:30}
|
||||
|
||||
ct.db-version=${DB_VERSION:1234}
|
||||
|
||||
ct.encoding=windows-1251
|
||||
|
||||
#Batch size and global pipeline timeout
|
||||
|
|
|
|||
|
|
@ -36,4 +36,6 @@ public class CreditTrackerSettings {
|
|||
|
||||
private Integer batchSize;
|
||||
private Integer timeout;
|
||||
|
||||
private String dbVersion;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package ru.nbch.credit_tracker.entities.app;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class AppVersion {
|
||||
private String dbVersion;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package ru.nbch.credit_tracker.mapper.signal;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import ru.nbch.credit_tracker.entities.app.AppVersion;
|
||||
|
||||
@Mapper
|
||||
public interface AppVersionMapper {
|
||||
AppVersion getAppVersion();
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package ru.nbch.credit_tracker.service;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.nbch.credit_tracker.config.settings.CreditTrackerSettings;
|
||||
import ru.nbch.credit_tracker.entities.app.AppVersion;
|
||||
import ru.nbch.credit_tracker.mapper.signal.AppVersionMapper;
|
||||
|
||||
@Service
|
||||
public class DbVersionValidationService implements InitializingBean {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final AppVersionMapper appVersionMapper;
|
||||
private final CreditTrackerSettings settings;
|
||||
|
||||
@Autowired
|
||||
public DbVersionValidationService(AppVersionMapper appVersionMapper, CreditTrackerSettings settings) {
|
||||
this.appVersionMapper = appVersionMapper;
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
String expectedDbVersion = settings.getDbVersion();
|
||||
|
||||
if (StringUtils.isEmpty(expectedDbVersion)) {
|
||||
log.error("expected database version is not specified in the settings.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
log.info("expected DB version: {}", expectedDbVersion);
|
||||
|
||||
AppVersion appVersion = appVersionMapper.getAppVersion();
|
||||
if (appVersion == null || StringUtils.isEmpty(appVersion.getDbVersion())) {
|
||||
log.error("couldn't load version from APP_VERSION database table.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
String actualVersion = appVersion.getDbVersion();
|
||||
|
||||
log.info("actual DB version: {}", actualVersion);
|
||||
|
||||
if (!expectedDbVersion.equals(actualVersion)) {
|
||||
log.error("expected database version does not match actual database version");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
log.info("Database version validation complete: {}", actualVersion);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="ru.nbch.credit_tracker.mapper.signal.AppVersionMapper">
|
||||
|
||||
<resultMap id="appVersionResultMap" type="ru.nbch.credit_tracker.entities.app.AppVersion">
|
||||
<result property="dbVersion" column="db_version"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="getAppVersion" resultMap="appVersionResultMap">
|
||||
SELECT db_version FROM app_version
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
CREATE TABLE signals_user_packages (
|
||||
CREATE TABLE app_version (
|
||||
DB_VERSION varchar(12)
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue