Skip to content

Suggestion for a single-file migration (some indexes were removed) #1129

@alec-c4

Description

@alec-c4

Hey!
I'd like to suggest a single-file migration with some indexes removed because of recommendations from active_record_doctor

class AddActsAsTaggableOn < ActiveRecord::Migration[7.1]
  def change
    create_table :tags, id: :uuid do |t|
      t.string "name"
      t.integer "taggings_count", default: 0

      t.timestamps
    end

    add_index :tags, :name, unique: true

    create_table :taggings, id: :uuid do |t|
      t.references :tag, foreign_key: {to_table: :tags}, type: :uuid
      t.references :taggable, polymorphic: true, type: :uuid
      t.references :tagger, polymorphic: true, type: :uuid
      t.string "context", limit: 128
      t.string "tenant", limit: 128

      t.timestamps
    end

    add_index :taggings, %i[taggable_id taggable_type context], name: "taggings_taggable_context_idx"
    add_index :taggings, :tagger_id
    add_index :taggings, :context
    add_index :taggings, %i[taggable_id taggable_type tagger_id context], name: "taggings_idy"
    add_index :taggings, :tenant
  end
end

Also, I've added uuid because I use it for indexes in PostgreSQL.

From my point of view it looks cleaner and easy to read/support.

If it is ok - I'll create PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions