编程知识 cdmana.com

Spring boot read set configuration to realize integrity check of service database

Catalog

yml Verify configuration

Java bean Injection allocation


In projects with technical support , Technical support does things carelessly , Results in inconsistent data structure integrity , So we need to develop the metadata used 、 Physical watch 、 Trigger, etc .

yml Verify configuration

# -------------- System database related integrity verification --------------- Start -------------
system:
  validator:
    metadata: # System metadata table field validation 
      enabledValidateFieldCase: true #  Whether to enable metadata registry field case verification , Default true
      validateUpperCase: true #  Whether it is to verify capitalization (true: Capitalization , false: A lowercase letter ), Default true
      validateDuplicateTables: #  Duplicate tables need to be validated 
      validateDuplicateRowsEnabled: false #  Whether to verify that there are duplicate database table records 
    table:  # Easy to ignore physical table validation 
      enabledValidatePhysicTable: true #  Whether to turn on physical table verification , Default true
      enabledValidateByStrict: true #  Whether to use strict verification mode (false: Generally, only the table name is needed for verification tablename,true: Strict verification requires 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:  # Whether the trigger exists verification 
      enabledValidateTrigger: true #  Whether trigger verification is enabled , Default true
      enabledValidateByStrict: true #  Whether to use strict verification mode (false: Generally, only the table name is needed for verification tablename,true: Strict verification requires 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
  # -------------- System database related integrity verification --------------- end -------------

Java bean Injection allocation

Metadata configuration :

/**
 * @Copyright: 2019-2021
 * @FileName: MetadataValidator.java
 * @Author: PJL
 * @Date: 2020/9/22 17:21
 * @Description:  Metadata validator 
 */
@Slf4j
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "system.validator.metadata")
@ConditionalOnProperty(name = "system.validator.metadata.enabledValidateFieldCase", havingValue = "true", matchIfMissing = true)
public class MetadataValidator {
    /**
     *  Metadata validation field capitalization 
     */
    Boolean validateUpperCase;

    /**
     *  Duplicate database tables need to be validated 
     */
    List<String> duplicateTables;

    /**
     *  Need to verify whether there are duplicate records in the table 
     */
    Boolean validateDuplicateRowsEnabled;
   
//.....

}

Table structure :

/**
 * @Copyright: 2019-2021
 * @FileName: TableValidator.java
 * @Author: PJL
 * @Date: 2020/9/23 16:15
 * @Description:  Special table check 
 */
@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:  Trigger verification 【 Whether triggers are created for validation 】
 */
@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;
 
    //......

}

 

版权声明
本文为[boonya]所创,转载请带上原文链接,感谢

Scroll to Top