-
Notifications
You must be signed in to change notification settings - Fork 78
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
Conversation
I suspect the reason #239 was able to get around LHM constraints was because it consolidated everything into a |
Oof yeah good shout @sambostock, whether we use Given the apps that use LHMs are a minority, we should just be able to ship this, and any app that requires use of LHMs can delete this migration and rewrite it as an LHM if need be (I think only Partners had an issue with this)? |
While I do agree it's probably fine to ship as is and let consumers rewrite migrations as LHM, Shopify's data stores best practices recommend everyone use LHM for all table changes, so I'm not sure how uncommon it is internally. That said, the only other thing we could do would be to try to detect LHM and generate an appropriate migration, but I don't know if that makes sense. |
# frozen_string_literal: true | ||
class RemoveIndexOnTaskName < ActiveRecord::Migration[6.1] | ||
def up | ||
change_table(:maintenance_tasks_runs) do |t| |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😄
There was a problem hiding this comment.
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.
Yeah, it's a really good point @sambostock - it's tricky to find the balance between making this meet our internal best practices vs trying to keep things conventional for use externally. Looking at the dependency list in SDB, there are a number of gems using Edit: After reviewing how LHMs can be used with AR migrations, if we keep the |
For: #342
Confirmed that the index on just
:task_name
is redundant given our composite index on[:task_name, :created_at]
. We can remove it.I think we need to remove the index from the table itself in a
change_table
block (instead of using https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-remove_index) due to LHM constraints (as mentioned here, modifying indexes outside of table blocks seems to pose problems for LHMs).