ctran/annotate_models

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

Opened this issue · 1 comments

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

Cause:
#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

I have the exact same issue.