tanoconsulting/datavalidatorbundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tanoconsulting/datavalidatorbundle

Composer 安装命令:

composer require tanoconsulting/datavalidatorbundle

包简介

A tool to validate Data stored in Databases and Filesystems

README 文档

README

Goals

Allow checking integrity of data in a database, going beyond what the database schema definition enforces.

Allow checking the integrity of a set of files (WIP).

Usecase

There are many scenarios in which usage of the constraints configured in a database schema is not sufficient to enforce data integrity, such as f.e.:

  • the db engine in use not supporting advanced/complex data validation constraints
  • the db engine in use does support advanced data validation constraints, but those are not being used
  • data integrity constraints which are too complex to express easily using the db engine
  • db native constraints having been disabled for speed during mass import operations
  • constraints having been implemented in application code, with multiple apps writing to the database

In all those cases, a separate tool which can validate that the data stored in the database adheres to a set of rules can come in handy.

Requirements

  • php 7.3 or later
  • a database supported by Doctrine DBAL (2.11 or 3.0 or later)
  • Symfony components: see composer.json

Quick start

  1. the set of constraints can be defined in a yaml or json file. This sample shows the supported syntax, using yaml:

    constraints:
      -
        ForeignKey:
          child:
            ezapprove_items: collaboration_id
          parent:
            ezcollab_item: id
      -
        ForeignKey:
          child:
            ezbinaryfile: [contentobject_attribute_id, version]
          parent:
            ezcontentobject_attribute: [id, version]
       -
        ForeignKey:
          child:
            ezcontentobject: id
          parent:
            ezcontentobject_version: contentobject_id
          except: 'ezcontentobject.status = 1 AND ezcontentobject_version.status = 1'
      -
        Query:
          name: classes_with_same_identifier
          sql: 'SELECT identifier, COUNT(*) AS identical_identifiers FROM ezcontentclass WHERE version = 0 GROUP BY identifier HAVING COUNT(*) > 1'
          # skip the validation of this constraint in a silent manner if the table is missing by using the line below:
          requires: {table: ezcontentclass}
  2. run the validation command

     php bin/console datavalidator:validate:database --config-file=<my_schema_constraints.yaml>
    

    This presumes that your application has set up a database connection configuration doctrine named default. If that is not the case, you can run:

     php bin/console datavalidator:validate:database --config-file=<my_schema_constraints.yaml> --database=<mysql://user:pwd@localhost/mydb>
    

    If you want to list the validations constraints without validating them run:

     php bin/console datavalidator:validate:database --config-file=<my_schema_constraints.yaml> --dry-run
    

    By default the results show the number of database rows found which violate each constraint. To see the data of those rows instead, use:

     php bin/console datavalidator:validate:database --config-file=<my_schema_constraints.yaml> --display-data
    

Constraints currently supported

  • foreign key definitions
  • custom sql queries

See the doc/samples folder for examples constraints of well-known applications' database schemas.

More advanced usage

Defining validation constraints in your code

Instead of using a dedicated configuration file on the command line, you can configure the validation constraints in code, either:

  • by setting a value to configuration parameter data_validator.constraints.database, or
  • by tagging services with the data_validator.constraint_provider.database tag. Those services will have to implement a public method getConstraintDefinitions() that returns all the relevant constraints definitions

Creating your own constraint types

WIP

Troubleshooting

  • Use the -v command line option to see details of execution

  • If the execution of the constraint validation is taking a long time, you can use CTRL-C to stop execution halfway: the script will exit gracefully printing any violation found up to that point

  • To avoid excessive memory usage from large queries, when running Symfony in "debug mode", such as commonly for "dev" envs, add the --no-debug option to your commands. If possible, use a non-debug Symfony env.

  • If you still get an 'allowed memory size' fatal error, run the commands with php -d memory_limit=-1.

FAQ

  • Q: can I run the validations in a Controller or Event instead of a cli command? A: technically yes, but it is generally not recommended, as the database queries used for validating the whole data set might take long to execute

Thanks

Code based on the Symfony/Validator component; thanks to all its developers!

License Latest Stable Version Total Downloads

tanoconsulting/datavalidatorbundle 适用场景与选型建议

tanoconsulting/datavalidatorbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 208 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「validation」 「constraint」 「compliance」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tanoconsulting/datavalidatorbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tanoconsulting/datavalidatorbundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 tanoconsulting/datavalidatorbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 208
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2021-03-01