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

add index by user_id on classifications #56

Merged
merged 1 commit into from
Apr 2, 2024
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
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
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
# 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"
yuenmichelle1 marked this conversation as resolved.
Show resolved Hide resolved
end

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