toptal / database_validations

Database validations for ActiveRecord
MIT License
535 stars 13 forks source link

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

Closed pirj closed 3 years ago

pirj commented 3 years ago

Hey @djezzzl ! :wave:

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.

djezzzl commented 3 years ago

I like the idea of the check but it seems that you confused the gem with database_consistency.

Would you like to contribute with such idea?

pirj commented 3 years ago

confused the gem with database_consistency.

100% guilty. Do you want me to open an issue there and close this one, or can you transfer it there?

Would you like to contribute with such idea?

Absolutely. On my current project, we're going through the process of enforcing consistency, but it's not something that happens overnight. I'll surely be happy to improve the topic when I'm out of other things that database_consistency can detect. Might be earlier, but no promises.

pirj commented 3 years ago

Moved to https://github.com/djezzzl/database_consistency/issues/91

djezzzl commented 3 years ago

100% guilty. Do you want me to open an issue there and close this one, or can you transfer it there?

It's up to you 👍 As I'd like to see a PR some day 😄

Absolutely. On my current project, we're going through the process of enforcing consistency, but it's not something that happens overnight. I'll surely be happy to improve the topic when I'm out of other things that database_consistency can detect. Might be earlier, but no promises.

Thank you, take your time 👍 And let me know if you would need any help with that.