{"id":15288797,"url":"https://github.com/soulfly/unique_validation_inspector","last_synced_at":"2025-04-09T09:08:14.127Z","repository":{"id":23853800,"uuid":"99913723","full_name":"soulfly/unique_validation_inspector","owner":"soulfly","description":"A Rake task that helps you find unique validations in Rails models that do not have proper DB indexes.","archived":false,"fork":false,"pushed_at":"2025-02-21T19:16:07.000Z","size":53,"stargazers_count":26,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T02:22:58.209Z","etag":null,"topics":["activerecord","gem","index","rails","ruby","ruby-gem","ruby-on-rails","uniqueness","validation"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soulfly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2017-08-10T10:59:44.000Z","updated_at":"2022-06-12T02:45:57.000Z","dependencies_parsed_at":"2025-03-16T04:02:45.893Z","dependency_job_id":null,"html_url":"https://github.com/soulfly/unique_validation_inspector","commit_stats":{"total_commits":34,"total_committers":3,"mean_commits":"11.333333333333334","dds":"0.17647058823529416","last_synced_commit":"fa0050358bbff0331a6473bec41241de1f8eb2d0"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soulfly%2Funique_validation_inspector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soulfly%2Funique_validation_inspector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soulfly%2Funique_validation_inspector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soulfly%2Funique_validation_inspector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soulfly","download_url":"https://codeload.github.com/soulfly/unique_validation_inspector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008630,"owners_count":21032556,"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","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","gem","index","rails","ruby","ruby-gem","ruby-on-rails","uniqueness","validation"],"created_at":"2024-09-30T15:53:13.526Z","updated_at":"2025-04-09T09:08:14.108Z","avatar_url":"https://github.com/soulfly.png","language":"Ruby","readme":"# UniqueValidationInspector\n\n![build passing](https://travis-ci.org/soulfly/unique_validation_inspector.svg?branch=master)\n[![Gem Version](https://badge.fury.io/rb/unique_validation_inspector.svg)](https://badge.fury.io/rb/unique_validation_inspector)\n\nA Rake task that helps you find unique validations in models that do not have proper DB indexes.\n\nIf uniqueness validation is enabled, Rails will look for existing records before performing **Model.create**, **Model.save**, **Model.update** ... operations. If a record was found the validation fails and the transaction will be rolled back, if not the record will be saved.\n\nFor example, you have **User** model and uniqueness validation for **facebook_id** field. The following SQL query will be performed on validation:\n\n```sql\n SELECT  1 AS one FROM `users` WHERE (`users`.`facebook_id ` = 1523123128921623) LIMIT 1\n```\nIf you do not have DB index for **facebook_id** field then your **Model.create**, **Model.save**, **Model.update** ... operations will be slower and slower with user base grow.\n\nSo this gem is here to notify you about it.\n\nRead [Rails: make sure you have proper DB indexes for your model’s unique validations](https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f) article to understand what kind of performance issues you may have without proper indexes.\n\nAlso read [How I Reduced my DB Server Load by 80%](https://schneems.com/2017/07/18/how-i-reduced-my-db-server-load-by-80/) article.\n\n## Supported versions\n* Ruby 1.8.7, 1.9.2, 1.9.3, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5\n\n* Rails 3.0.x, 3.1.x, 3.2.x, 4.0.x, 4.1.x, 5.0.x, 5.1.x, 5.2.x\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'unique_validation_inspector'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install unique_validation_inspector\n\n## Usage\n\nJust run the following command in your Rails app directory:\n\n    $ rake inspect_unique_validations\n\n## Output\n\n```bash\nYou have the following unique validations:\n\nModel 'Application':\n[:title] (scope 'account_id'). Index exists: false\n\nModel 'User':\n[:email] (scope 'application_id'). Index exists: true\n[:login] (scope 'application_id'). Index exists: false\n[:facebook_id] (scope 'application_id'). Index exists: true\n[:twitter_id] (scope 'application_id'). Index exists: false\n[:external_user_id] (scope 'application_id'). Index exists: false\n[:blob_id]. Index exists: true\n```\nAll things with **Index exists: false** are problematic and you should fix it by adding proper DB indexes.\n\nConsider use one of the following solutions to resolve above issues:\n* Add proper DB index.\n* Move unique validation to DB level.\nMore info in the article https://medium.com/@igorkhomenko/rails-make-sure-you-have-proper-db-indexes-for-your-models-unique-validations-ffd0364df26f\n\n## Copyright\n\nCopyright © 2017 Igor Khomenko. See LICENSE file for further details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoulfly%2Funique_validation_inspector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoulfly%2Funique_validation_inspector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoulfly%2Funique_validation_inspector/lists"}