Springboot reads the collection configuration to realize the integrity check of the service database

table of Contents

yml verification configuration

Java bean injection configuration


In projects where technical support is involved, technical support does things carelessly, resulting in inconsistent data structure integrity, so developers are required to start verification of the metadata, physical tables, triggers, etc. used.

yml verification configuration

# --------------系统数据库相关完整性校验---------------开始-------------
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 injection configuration

Metadata configuration:

/**
 * @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;
   
//.....

}

Table Structure:

/**
 * @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;

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

trigger:

/**
 * @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;
 
    //......

}

 

Guess you like

Origin blog.csdn.net/boonya/article/details/108785056