class RuboCop::Cop::Discourse::NoAddReferenceOrAliasesActiveRecordMigration

end
SQL
index_posts_on_image_upload_id ON posts USING btree (image_upload_id)
CREATE INDEX CONCURRENTLY IF NOT EXISTS
execute <<~SQL
SQL
ADD COLUMN IF NOT EXISTS image_upload_id bigint
ALTER TABLE posts
execute <<~SQL
def up
disable_ddl_transaction!
# good
end
# or t.belongs_to :image_upload when doing create_table do |t|
# or t.references :image_upload when doing create_table do |t|
# or add_belongs_to :posts, :image_upload
add_reference :posts, :image_upload
def up
# bad
@example
can pick a better name for the index at the same time.
IF NOT EXISTS cases, which enable re-runnable migrations. Also we
concurrently using hand-written SQL. This also allows us to handle
the new column (with any defaults and options required) and the index
Instead, inside a disable_ddl_transaction! migration we should create
which is a nightmare for large tables.
add_reference adds an index at the same time, but not concurrently,
some unexpected things in the background. For example, by default
in ActiveRecord migrations are magic, and they all do
* t.belongs_to
* t.references
* add_belongs_to
* add_reference
The methods:

def on_send(node)

def on_send(node)
  if [
       using_add_reference?(node),
       using_add_belongs_to?(node),
       using_t_references?(node),
       using_t_belongs_to?(node),
     ].none?
    return
  end
  add_offense(node, message: MSG)
end