{"repo":"toptal/database_validations","free":true,"listed":false,"github":"https://github.com/toptal/database_validations","clone":"git clone https://github.com/toptal/database_validations.git","description":"Database validations for ActiveRecord","language":"Ruby","stars":569,"topics":["activerecord","ruby-on-rails","ruby","database","performance"],"license":"MIT","category":"databases-storage","readme_excerpt":"DatabaseValidations DatabaseValidations helps you to keep the database consistency with better performance. Right now, it supports only ActiveRecord. The more you use the gem, the more performance increase you have. Try it now! Installation Add this line to your application's Gemfile: And then execute: Or install it yourself as: Have a look at example application for details. Benchmark (code) Imagine, you have User model defines as and then replace with you will get the following performance improvement: db belongs to Supported databases are PostgreSQL , MySQL , and SQLite . Usage Problem ActiveRecord's belongs to has optional: false by default. Unfortunately, this approach does not ensure existence of the related object. For example, we can skip validations or remove the related object after we save the object. After that, our database becomes inconsistent because we assume the object has his relation but it does not. db belongs to solves the problem using foreign key constraints in the database also providing backward compatibility with nice validations errors. Pros and Cons Advantages : - Ensures relation existence because it uses foreign keys constraints. - Checks the existence of proper foreign key constraint at the boot time. Use ENV['SKIP DB UNIQUENESS VALIDATOR INDEX CHECK'] = 'true' if you want to skip it in some cases. (For example, when you run migrations.) Note: we skip it for the abstract classes. - It's almost two times faster because it skips unnecessary SQL qu","default_branch":null,"files":null,"tree":[],"storefront":"/r/toptal","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/toptal/database_validations/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}