Git Product home page Git Product logo

database_validations's People

Contributors

brunoarueira avatar dependabot-preview[bot] avatar djezzzl avatar jduff avatar palkan avatar pirj avatar pyromaniac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

database_validations's Issues

Idea: Replace `dependent: :delete`/`dependent: :nullify` with FK `on_delete:`/`on_update:`

Hey @djezzzl ! ๐Ÿ‘‹

Cascade deletion is sometimes a very expensive operation.
In case the association is defined as dependent: :delete, it is possible to rely on the database to perform the deletion instead.
See :on_delete/:on_update.

Disclaimer: I clearly understand that dependent: :destroy should remain ignored, as destroy also runs callbacks.

Would it make sense to detect this and suggest changing the FK in such a way that the DB handles cascade deletion/nullification?

Sorry for not being verbose. I'd love to validate the idea with you first, and elaborate if you support it.

Merge into Rails?

What do you think about opening some of the behavior here as a PR against ActiveRecord or whatever relevant Rails core gem? Being as relationships are foundational to models I would think they would welcome any performance & logical enhancements to them.

Tasks for contribution

Hi, thank you for using our gem!

Here we have the list with opened tasks to do:

  • Replace where option with conditions for validates_db_uniqueness_of so validates_db_uniqueness_of becomes easier replacement for validates_uniqueness_of.

  • Add test coverage analyzer to CI and badge to README

  • Foreign keys can accept NULL values, so we can support optional: true option for db_belongs_to

  • Add support of Rails.application.config.active_record.belongs_to_required_by_default = false

  • Matchers validates_presence_of and belong_to should work

You can also suggest a new feature! Any contribution is welcome!

Incompatible with postgis adapter

Adding gem 'activerecord-postgis-adapter' to your Gemfile and configuring database.yml to use the postgis adapter:

default: &default
  adapter: postgis
  encoding: unicode
  ....

Will yield a system that is incompatible with database_validations, because the adapter name doesn't match, postgres.

Can you extend your supported adapters to also support postgres with the GIS extension?

Thanks!

db_belongs_to with optional: true

db_belongs_to :company, optional: true
gives a validation error:
ActiveRecord::RecordInvalid: Validation failed: Company must exist
on empty value (company_id=nil), although
belongs_to :company, optional: true
in the same situation does not give an error

Doesn't work with nested attributes / autosave associations.

When using nested attributes the associated objects are autosaved, which either does a direct insert or saves with validate: false as you you can see here. This means when we get to the create_or_update defined in this gem here validate is false and the exceptions are not handled.

This is likely true of any collection associations that are autosaved, I only noticed it when using nested attributes though.

Running Specs

How do I configure the database to run specs for this project.

`update` causing unexpected RecordNotUnique error

I recently upgraded from v0.9.0 to 1.0.1 in order to address the deprecation warnings for connection config. It has caused some of my tests to fail in a way that I wasn't expecting given the details outlined in the change log and I think it may be a bug.

I have a model called User which has many Questions. Questions must be unique by name for a given user. We have a controller for adding questions to a user which has a method along the lines of user.update(user_params_with_questions). The params include an array of questions to add.

In the failing test cases case we're attempting to add two new questions with the same name to a user as part of the same update operation. Previously, this returned false but it's now raising a RecordNotUnique error. If I add them sequentially I get the expected behaviour.

I went through a process of progressively upgrading from the original version to pinpoint when the breaking changes were introduced and found that 0.9.4 was the culprit. This is consistent with the stack trace which points to /lib/database_validations/lib/validations.rb:20:in create_or_update'`:

def create_or_update(*args, &block)
      options = args.extract_options!

      if options[:validate] == false
        super
      else
        rescue_from_database_exceptions { super }
      end
    end

So, my assumption is that something is causing the validate option to be interpreted as false and the super behaviour is being called vs the rescue_from_database_exceptions function.

Additional context:

Rails version: 6.1.4.1
Ruby version: 2.6.2

Any ideas about what might be going on here? Or additional behaviour that would help figure it out? Thanks in advance!

Testing case_sensitive: true

Hey,

How can I test on RSpec if validate_db_uniqueness_of is case_sensitive: true?

The matcher at https://github.com/toptal/database_validations/blob/master/lib/database_validations/rspec/uniqueness_validator_matcher.rb#L10 only has options for case insensitive.

Checking the diff from version 0.8.10 to latest master, the default for Rails 6 case_sensitive is nil.
v0.8.10...master#diff-0b72b6ffa59687cb5bb851b40f2ad87aR62
This causes all specs to fail if the validation is case_sensitive: true.

is this a limitation of the matcher? Are there plans to improve it?

Any help is appreciated.

Best Regards,
Ronaldo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.