djezzzl / database_consistency

The tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models.
MIT License
1.02k stars 43 forks source link

ForeignKeyCascadeChecker default mapping #186

Closed pyromaniac closed 1 year ago

pyromaniac commented 1 year ago

Hey @djezzzl I believe that the mapping here https://github.com/djezzzl/database_consistency/blob/a2be80b47fc9cc165c302cf2da60a03a5dfd473d/lib/database_consistency/checkers/association_checkers/foreign_key_cascade_checker.rb#L20-L21 is not entirely correct. Accordingly to https://stackoverflow.com/questions/60043008/when-to-use-nothing-or-restrict-for-on-delete-with-ecto the default NO ACTION value also raises an error, it is just deferred. But for this purpose it would be perfect to have something like:

      OPTION_TO_CASCADE = {
        delete: :cascade,
        delete_all: :cascade,
        nullify: :nullify,
        restrict_with_exception: [nil, :restrict],
        restrict_with_error: [nil, :restrict]
      }.freeze

WDYT?

djezzzl commented 1 year ago

Hi @pyromaniac,

Yes, it seems you're correct. Thank you for sharing this! Would you like to make a PR for that?

I'm sorry it took me long to look at the issue.

pyromaniac commented 1 year ago

Yes, will do soon

djezzzl commented 1 year ago

Thank you! I would be happy to merge and release immediately.