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

Remove redundant index on :task_name #346

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions db/migrate/20210225152418_remove_index_on_task_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
class RemoveIndexOnTaskName < ActiveRecord::Migration[6.1]
def up
change_table(:maintenance_tasks_runs) do |t|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to use remove_index and add_index directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I could see using this over remove_index and add_index directly is that it makes it easier to change it to an LHM:

class RemoveIndexOnTaskName < ActiveRecord::Migration[6.1]
  def up
    change_table(:maintenance_tasks_runs) do |t|
      t.remove_index(:task_name)
    end
  end

  def down
    change_table(:maintenance_tasks_runs) do |t|
      t.index(:task_name)
    end
  end
end
require 'lhm'

class RemoveIndexOnTaskName < ActiveRecord::Migration[6.1]
  def up
    Lhm.change_table :maintenance_tasks_runs do |t|
      t.remove_index(:task_name)
    end
  end

  def down
    Lhm.change_table :maintenance_tasks_runs do |t|
      t.index(:task_name)
    end
  end
end

Not sure if if this is something we care about that much though 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup it's really nice if it lets people adapt it more easily to LHM.

t.remove_index(:task_name)
end
end

def down
change_table(:maintenance_tasks_runs) do |t|
t.index(:task_name)
end
end
end
3 changes: 1 addition & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_01_12_141723) do
ActiveRecord::Schema.define(version: 2021_02_25_152418) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -56,7 +56,6 @@
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["task_name", "created_at"], name: "index_maintenance_tasks_runs_on_task_name_and_created_at", order: { created_at: :desc }
t.index ["task_name"], name: "index_maintenance_tasks_runs_on_task_name"
end

create_table "posts", force: :cascade do |t|
Expand Down