Skip to content

Commit

Permalink
LG-1384 Fix phone configuration index (#2989)
Browse files Browse the repository at this point in the history
**Why**: To prevent full table scans and db outages

**How**: Add new index prefixed with user_id to phone_configurations.  Drop old index.
  • Loading branch information
stevegsa authored Jun 4, 2019
1 parent a409c06 commit 7da6185
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions db/migrate/20190604110233_fix_phone_configuration_index.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class FixPhoneConfigurationIndex < ActiveRecord::Migration[5.1]
disable_ddl_transaction!

def up
add_index(
:phone_configurations,
%i[user_id made_default_at created_at],
algorithm: :concurrently,
name: 'index_phone_configurations_on_made_default_at',
)
remove_index :phone_configurations, %i[made_default_at created_at]
end

def down
remove_index :phone_configurations, %i[user_id made_default_at created_at]
add_index(
:phone_configurations,
%i[made_default_at created_at],
algorithm: :concurrently,
)
end
end
4 changes: 2 additions & 2 deletions 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: 20190529120309) do
ActiveRecord::Schema.define(version: 20190604110233) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -200,7 +200,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "made_default_at"
t.index ["made_default_at", "created_at"], name: "index_phone_configurations_on_made_default_at_and_created_at"
t.index ["user_id", "made_default_at", "created_at"], name: "index_phone_configurations_on_made_default_at"
t.index ["user_id"], name: "index_phone_configurations_on_user_id"
end

Expand Down

0 comments on commit 7da6185

Please sign in to comment.