-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
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
endAlso, 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels