Skip to content

Commit

Permalink
add index by user_id on classifications (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuenmichelle1 authored Apr 2, 2024
1 parent fd99643 commit bf69893
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# Timescale currently does not support creating indexes concurrently. See: https://github.com/timescale/timescaledb/issues/504
# This means that we cannot avoid write locks.
# Timescale does offer adding indexes on a transaction per chunk basis.
# See: https://docs.timescale.com/api/latest/hypertable/create_index/ for more details.

class AddIndexByUserIdForClassifications < ActiveRecord::Migration[7.0]
disable_ddl_transaction!

def change
execute <<~SQL
CREATE INDEX index_classification_events_on_user_id ON classification_events(user_id) WITH (timescaledb.transaction_per_chunk);
SQL
end
end
3 changes: 2 additions & 1 deletion 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[7.0].define(version: 2023_11_06_170457) do
ActiveRecord::Schema[7.0].define(version: 2024_03_28_183306) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "timescaledb"
Expand All @@ -29,6 +29,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["event_time"], name: "classification_events_event_time_idx", order: :desc
t.index ["user_id"], name: "index_classification_events_on_user_id"
end

create_table "classification_user_groups", primary_key: ["classification_id", "event_time", "user_group_id", "user_id"], force: :cascade do |t|
Expand Down

0 comments on commit bf69893

Please sign in to comment.