Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alec-c4 opened this issue Aug 7, 2024 · 0 comments
Open

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

alec-c4 opened this issue Aug 7, 2024 · 0 comments

Comments

@alec-c4
Copy link

alec-c4 commented Aug 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant