gregnavis / active_record_doctor

Identify database issues before they hit production.
MIT License
1.76k stars 55 forks source link

Rails 7 Active Support not following ignore_tables configuraton #146

Closed ali-hiringthing closed 1 year ago

ali-hiringthing commented 1 year ago

With Rails 7, when attempting to add the active support tables, using the following config snippet from the readme,

  global :ignore_tables, [
    # Ignore internal Rails-related tables.
    "ar_internal_metadata",
    "schema_migrations",
    "active_storage_blobs",
    "active_storage_attachments",
    "action_text_rich_texts",

    # Add project-specific tables here.
    "legacy_users"
  ]

results in -

add a `presence` validator to ActiveStorage::VariantRecord.variation_digest - it's NOT NULL but lacks a validator
add a `presence` validator to ActiveStorage::Blob.key - it's NOT NULL but lacks a validator
add a `presence` validator to ActiveStorage::Blob.filename - it's NOT NULL but lacks a validator
add a `presence` validator to ActiveStorage::Blob.byte_size - it's NOT NULL but lacks a validator
add a `presence` validator to ActiveStorage::Attachment.name - it's NOT NULL but lacks a validator
add a `presence` validator to ActiveStorage::Attachment.record_type - it's NOT NULL but lacks a validator

Using the following config does bypass the issue:

detector :missing_presence_validation,
  ignore_models: [
    "ActiveStorage::Attachment",
    "ActiveStorage::Blob", 
    "ActiveStorage::VariantRecord"
  ] 

Hoping that will point you guys in the right direction. Thanks!

fatkodima commented 1 year ago

That is a correct behaviour from the gem, because you need to use ignore_models for MissingPresenceValidation, not ignore_tables.

gregnavis commented 1 year ago

@fatkodima is correct: presence validators are inherently related to models, not tables. That's why the setting is ignore_models.