Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Check constraint checker #181

Open
chaadow opened this issue Feb 13, 2023 · 2 comments
Open

[Feature] Check constraint checker #181

chaadow opened this issue Feb 13, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@chaadow
Copy link
Contributor

chaadow commented Feb 13, 2023

Hi,
First, thanks for this wonderful gem.

I was wondering if adding a checker between "validates_numericality_of" and a CHECK constraint can be easily implemented.

I can try to look into it by looking into how the presence validator is implemented if you consider this valuable.

@djezzzl
Copy link
Owner

djezzzl commented Mar 5, 2023

Hi @chaadow,

Sorry that it took so long for me to answer you!

First, thank you for your kind words; I'm glad the gem is valuable.

Could you please say if the CHECK constraint is somewhat standard? I just think what would be the way to compare what is defined in CHECK with what should be there.

The most effortless check would ensure some CHECK constraint on the field with validates_numericality_of validation.

Would you find this helpful?

@chaadow
Copy link
Contributor Author

chaadow commented Mar 5, 2023

Yes I believe it's quite standard

Yes i'm thinking of 2-way checkers. One that would autocorrect by adding a migration like this :

class CreateBooks < ActiveRecord::Migration
  def change
    add_check_constraint :books, "price > 100", name: "price_check"
  end
end

and the other way around, where a check constraint exists on a column ( for numericality) but no validates_numericality_of in the model.

Another use case for a check constraint is for a NOT NULL :
image

Since it is functionally equivalent to the column constraint NOT NULL, it can avoid false positives for the validates_presence_of checker.

@djezzzl djezzzl added the enhancement New feature or request label Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants