Skip to content

Commit 16cf5d2

Browse files
committed
Update issue assignments to bigint
Fix issue ``` E, [2026-02-02T15:37:35.582127 #5] ERROR -- : [ActiveJob] [PopulateIssuesJob] [cffcb87a-a234-487b-9bf8-07fefe0c8213] Error performing PopulateIssuesJob (Job ID: cffcb87a-a234-487b-9bf8-07fefe0c8213) from Sidekiq(default) in 550.91ms: ActiveRecord::RangeError (PG::NumericValueOutOfRange: ERROR: integer out of range ): /app/vendor/bundle/ruby/3.2.0/gems/rack-mini-profiler-3.1.1/lib/patches/db/pg.rb:69:in `exec_params' /app/vendor/bundle/ruby/3.2.0/gems/rack-mini-profiler-3.1.1/lib/patches/db/pg.rb:69:in `exec_params' /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.8/lib/active_record/connection_adapters/postgresql_adapter.rb:768:in `block (2 levels) in exec_no_cache' /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares' ```
1 parent c26c26c commit 16cf5d2

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
class ChangeIssuesIdToBigint < ActiveRecord::Migration[7.0]
4+
# Disable transaction to allow running on large tables without locking for too long
5+
# You may want to run this during low-traffic periods
6+
disable_ddl_transaction!
7+
8+
def up
9+
# Change the id column from integer (serial) to bigint (bigserial)
10+
# This is necessary because the issues table has exceeded the 32-bit integer limit
11+
# Max integer: 2,147,483,647
12+
# Max bigint: 9,223,372,036,854,775,807
13+
14+
safety_assured do
15+
# Change the primary key column type
16+
execute "ALTER TABLE issues ALTER COLUMN id TYPE bigint"
17+
18+
# Change the sequence type to bigint as well
19+
execute "ALTER SEQUENCE issues_id_seq AS bigint"
20+
21+
# Also update foreign keys in issue_assignments that reference issues.id
22+
execute "ALTER TABLE issue_assignments ALTER COLUMN issue_id TYPE bigint"
23+
end
24+
end
25+
26+
def down
27+
safety_assured do
28+
# Note: This could fail if there are values > 2,147,483,647
29+
execute "ALTER TABLE issue_assignments ALTER COLUMN issue_id TYPE integer"
30+
execute "ALTER SEQUENCE issues_id_seq AS integer"
31+
execute "ALTER TABLE issues ALTER COLUMN id TYPE integer"
32+
end
33+
end
34+
end

db/schema.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2022_12_28_065556) do
13+
ActiveRecord::Schema[7.0].define(version: 2026_02_02_160000) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_stat_statements"
1616
enable_extension "plpgsql"
@@ -74,8 +74,8 @@
7474
t.index ["repo_id", "name", "path"], name: "index_doc_methods_on_repo_id_and_name_and_path", unique: true
7575
end
7676

77-
create_table "issue_assignments", id: :serial, force: :cascade do |t|
78-
t.integer "issue_id"
77+
create_table "issue_assignments", force: :cascade do |t|
78+
t.bigint "issue_id"
7979
t.datetime "created_at", precision: nil, null: false
8080
t.datetime "updated_at", precision: nil, null: false
8181
t.integer "repo_subscription_id"
@@ -84,7 +84,7 @@
8484
t.index ["repo_subscription_id", "delivered"], name: "index_issue_assignments_on_repo_subscription_id_and_delivered"
8585
end
8686

87-
create_table "issues", id: :serial, force: :cascade do |t|
87+
create_table "issues", force: :cascade do |t|
8888
t.integer "comment_count"
8989
t.string "url"
9090
t.string "repo_name"

0 commit comments

Comments
 (0)