{"id":19940633,"url":"https://github.com/krzysztoff1/db-validator","last_synced_at":"2025-09-30T07:31:31.013Z","repository":{"id":261679662,"uuid":"884966798","full_name":"krzysztoff1/db-validator","owner":"krzysztoff1","description":"DbValidator helps identify invalid records in your Rails application that don't meet model validation requirements","archived":false,"fork":false,"pushed_at":"2024-12-13T20:45:40.000Z","size":100,"stargazers_count":20,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T20:21:25.250Z","etag":null,"topics":["activerecord","rails","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/db_validator","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krzysztoff1.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-07T17:53:34.000Z","updated_at":"2025-07-17T01:13:58.000Z","dependencies_parsed_at":"2024-11-07T21:27:15.706Z","dependency_job_id":"8ee7ef20-4fa8-48ea-9890-045f37f87b1d","html_url":"https://github.com/krzysztoff1/db-validator","commit_stats":null,"previous_names":["krzysztoff1/db-validator"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/krzysztoff1/db-validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysztoff1%2Fdb-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysztoff1%2Fdb-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysztoff1%2Fdb-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysztoff1%2Fdb-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krzysztoff1","download_url":"https://codeload.github.com/krzysztoff1/db-validator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krzysztoff1%2Fdb-validator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274622077,"owners_count":25319559,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","rails","ruby"],"created_at":"2024-11-13T00:06:15.372Z","updated_at":"2025-09-30T07:31:30.735Z","avatar_url":"https://github.com/krzysztoff1.png","language":"Ruby","funding_links":[],"categories":["Ruby","Gems"],"sub_categories":["Articles"],"readme":"[![Gem Version](https://badge.fury.io/rb/db_validator.svg?icon=si%3Arubygems)](https://badge.fury.io/rb/db_validator)\n[![RSpec Tests](https://github.com/krzysztoff1/db-validator/actions/workflows/rspec.yml/badge.svg)](https://github.com/krzysztoff1/db-validator/actions/workflows/rspec.yml)\n\n# DbValidator\n\nDbValidator helps identify invalid records in your Rails application that don't meet model validation requirements. It finds records that became invalid after validation rule changes, and validates imported or manually edited data. You can use it to audit records before deploying new validations and catch any data that bypassed validation checks.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'db_validator'\n```\n\nThen execute:\n\n```bash\n$ bundle install\n```\n\n## Usage\n\n### Rake Task\n\nThe simplest way to run validation is using the provided rake task:\n\n#### Validate models in interactive mode\n\n\u003cimg width=\"798\" alt=\"Screenshot 2024-11-07 at 21 50 57\" src=\"https://github.com/user-attachments/assets/33fbdb8b-b8ec-4284-9313-c1eeaf2eab2d\"\u003e\n\n```bash\n$ rake db_validator:validate\n```\n\nThis will start an interactive mode where you can select which models to validate and adjust other options.\n\n#### Validate specific models\n\n```bash\n$ rake db_validator:validate models=user,post\n```\n\n#### Limit the number of records to validate\n\n```bash\n$ rake db_validator:validate limit=1000\n```\n\n#### Generate JSON report\n\n```bash\n$ rake db_validator:validate format=json\n```\n\n### Test Mode\n\nYou can test new validation rules before applying them to your models:\n\n```bash\n$ rake db_validator:test model=User rule='validates :name, presence: true'\n```\n\n#### Testing Email Format Validation\n\nHere's an example of testing email format validation rules:\n\n```bash\n# Testing invalid email format (without @)\n$ rake db_validator:test model=User rule='validates :email, format: { without: /@/, message: \"must contain @\" }'\n\nFound 100 records that would become invalid out of 100 total records.\n\n# Testing valid email format (with @)\n$ rake db_validator:test model=User rule='validates :email, format: { with: /@/, message: \"must contain @\" }'\n\nNo invalid records found.\n```\n\n#### Error Handling\n\nTrying to test a validation rule for a non-existent attribute will return an error:\n\n```\n❌ Error: Attribute 'i_dont_exist' does not exist for model 'User'\nAvailable columns: id, email, created_at, updated_at, name\n```\n\n### Ruby Code\n\nYou can also run validation from your Ruby code:\n\n#### Validate all models\n\n```ruby\nreport = DbValidator.validate\n```\n\n#### Validate with options\n\n```ruby\nreport = DbValidator.validate(\n  only_models: ['User', 'Post'],\n  limit: 1000,\n  report_format: :json\n)\n```\n\n## Report Format\n\n### Text Format (Default)\n\n```\nDbValidator Report\n==================\nFound invalid records:\n\nUser: 2 invalid records\nID: 1\n  email is invalid (actual value: \"invalid-email\")\nID: 2\n  name can't be blank (actual value: \"\")\n\nPost: 1 invalid record\nID: 5\n  title can't be blank (actual value: \"\")\n  category is not included in the list (allowed values: news, blog, actual value: \"invalid\")\n```\n\n### JSON Format\n\nThe JSON report is saved to a file in the `db_validator_reports` directory.\n\n```json\n{\n  \"User\": {\n    \"error_count\": 2,\n    \"records\": [\n      {\n        \"id\": 1,\n        \"errors\": [\n          \"email is invalid (actual value: \\\"invalid-email\\\")\"\n        ]\n      },\n      {\n        \"id\": 2,\n        \"errors\": [\n          \"name can't be blank (actual value: \\\"\\\")\"\n        ]\n      }\n    ]\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzysztoff1%2Fdb-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrzysztoff1%2Fdb-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrzysztoff1%2Fdb-validator/lists"}