annotate_models icon indicating copy to clipboard operation
annotate_models copied to clipboard

Additional index annotation to other table with same name but with prefix

Open choosen opened this issue 2 years ago • 1 comments

Annotate is adding us additional indexes to other table with same name but with prefix.

Cause: https://github.com/ctran/annotate_models/pull/405 provided code to remove table_name_prefix on index annotate, as some people have problem with public. prefix @ postgres. Fixing prefix this way maybe can be valid but is not universal.

We use table_name_prefix for domain module table prefixes like this:

module AccessControlSystems
  class BaseModel < ApplicationRecord
    self.abstract_class = true

    def self.table_name_prefix
      'access_control_systems_'
    end
  end
end
(...)
#
# Indexes
#
#  index_locations_on_contact_user_id  (contact_user_id) # <<<< it should not be here 
#
module AccessControlSystems
  class Location < BaseModel
  end
end

and we have common location table without table prefix:

(...)
#
# Indexes
#
#  index_locations_on_contact_user_id  (contact_user_id)
#
# Foreign Keys
# (...)  Foreign keys are fine
class Location < ApplicationRecord
end

We can also define table_name_prefix in AccessControlSystems::Location and the issue will be there

Commands

We annotate on migrate:

rake db:migrate

Version

  • annotate version 4.2.0 (4.1.X)
  • rails version 5.2.6
  • ruby version 2.6.9

choosen avatar Aug 16 '22 09:08 choosen

I have the exact same issue.

filipegiusti avatar Jun 23 '23 19:06 filipegiusti