Springboot读取集合配置实现服务数据库完整性校验

目录

yml验证配置

Java bean注入配置


在有技术支持参与的项目中,技术支持做事情马马虎虎,导致数据结构完整性不一致,于是要求开发对用到的元数据、物理表、触发器等进行启动校验。

yml验证配置

# --------------系统数据库相关完整性校验---------------开始-------------
system:
  validator:
    metadata: #系统元数据表字段验证
      enabledValidateFieldCase: true # 是否开启元数据注册表字段大小写验证,默认true
      validateUpperCase: true # 是否是验证大写(true:大写, false:小写),默认true
      validateDuplicateTables: # 需要验证重复的表
      validateDuplicateRowsEnabled: false # 是否验证数据库表记录存在重复
    table:  #易忽略物理表验证
      enabledValidatePhysicTable: true # 是否开启物理表校验,默认true
      enabledValidateByStrict: true # 是否使用严格校验模式(false:一般校验只需要表名tablename,true:严格校验需要schame.tablename)
      validateTables:
        - xh_ht.fs_yw_base_org
        - xh_ht.fs_yw_base_user
        - xh_yw.xh_user_online_tb
        - xh_yw.xh_trigger_records_tb
        - xh_yw.xh_user_contrast
    trigger:  #触发器是否存在验证
      enabledValidateTrigger: true # 是否开启触发器验证,默认true
      enabledValidateByStrict: true # 是否使用严格校验模式(false:一般校验只需要表名tablename,true:严格校验需要schame.tablename)
      validateTriggers:
        - xh_ht.org_insert_trigger
        - xh_ht.org_delete_trigger
        - xh_ht.org_update_trigger
        - xh_ht.user_insert_trigger
        - xh_ht.user_delete_trigger
        - xh_ht.user_update_trigger
  # --------------系统数据库相关完整性校验---------------结束-------------

Java bean注入配置

元数据配置:

/**
 * @Copyright: 2019-2021
 * @FileName: MetadataValidator.java
 * @Author: PJL
 * @Date: 2020/9/22 17:21
 * @Description: 元数据验证器
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.metadata")
@ConditionalOnProperty(name = "system.validator.metadata.enabledValidateFieldCase", havingValue = "true", matchIfMissing = true)
public class MetadataValidator {
    /**
     * 元数据验证字段大写
     */
    Boolean validateUpperCase;

    /**
     * 需要验证重复的数据库表
     */
    List<String> duplicateTables;

    /**
     * 需要验证表是否存在重复记录验证
     */
    Boolean validateDuplicateRowsEnabled;
   
//.....

}

表结构:

/**
 * @Copyright: 2019-2021
 * @FileName: TableValidator.java
 * @Author: PJL
 * @Date: 2020/9/23 16:15
 * @Description: 特殊表校验
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.table")
@ConditionalOnProperty(name = "system.validator.table.enabledValidatePhysicTable", havingValue = "true")
public class TableValidator {

    Boolean enabledValidateByStrict;

    List<String> validateTables;

    //................
}

触发器:

/**
 * @Copyright: 2019-2021
 * @FileName: TriggerValidator.java
 * @Author: PJL
 * @Date: 2020/9/23 16:14
 * @Description: 触发器校验【触发器是否创建进行验证】
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.trigger")
@ConditionalOnProperty(name = "system.validator.trigger.enabledValidateTrigger", havingValue = "true")
public class TriggerValidator {

    Boolean enabledValidateByStrict;

    List<String> validateTriggers;
 
    //......

}

猜你喜欢

转载自blog.csdn.net/boonya/article/details/108785056
今日推荐