Skip to content
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
34 changes: 34 additions & 0 deletions db/migrate/20260202160000_change_issues_id_to_bigint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

class ChangeIssuesIdToBigint < ActiveRecord::Migration[7.0]
# Disable transaction to allow running on large tables without locking for too long
# You may want to run this during low-traffic periods
disable_ddl_transaction!

def up
# Change the id column from integer (serial) to bigint (bigserial)
# This is necessary because the issues table has exceeded the 32-bit integer limit
# Max integer: 2,147,483,647
# Max bigint: 9,223,372,036,854,775,807

safety_assured do
# Change the primary key column type
execute "ALTER TABLE issues ALTER COLUMN id TYPE bigint"

# Change the sequence type to bigint as well
execute "ALTER SEQUENCE issues_id_seq AS bigint"

# Also update foreign keys in issue_assignments that reference issues.id
execute "ALTER TABLE issue_assignments ALTER COLUMN issue_id TYPE bigint"
end
end

def down
safety_assured do
# Note: This could fail if there are values > 2,147,483,647
execute "ALTER TABLE issue_assignments ALTER COLUMN issue_id TYPE integer"
execute "ALTER SEQUENCE issues_id_seq AS integer"
execute "ALTER TABLE issues ALTER COLUMN id TYPE integer"
end
end
end
8 changes: 4 additions & 4 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[7.0].define(version: 2022_12_28_065556) do
ActiveRecord::Schema[7.0].define(version: 2026_02_02_160000) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
enable_extension "plpgsql"
Expand Down Expand Up @@ -74,8 +74,8 @@
t.index ["repo_id", "name", "path"], name: "index_doc_methods_on_repo_id_and_name_and_path", unique: true
end

create_table "issue_assignments", id: :serial, force: :cascade do |t|
t.integer "issue_id"
create_table "issue_assignments", force: :cascade do |t|
t.bigint "issue_id"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.integer "repo_subscription_id"
Expand All @@ -84,7 +84,7 @@
t.index ["repo_subscription_id", "delivered"], name: "index_issue_assignments_on_repo_subscription_id_and_delivered"
end

create_table "issues", id: :serial, force: :cascade do |t|
create_table "issues", force: :cascade do |t|
t.integer "comment_count"
t.string "url"
t.string "repo_name"
Expand Down