From 8c1c9b2d30260e57f99fffaa5167335e68458df7 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 2 Mar 2023 16:17:44 +1100 Subject: [PATCH] FEATURE: add db:resize:notification_id task for growing table Under exceptional cases people may need to resize the notification table. This only happens on forums with a total of more than 2.5 billion notifications. This rake task can be used to convert all the notification columns to bigint to make more room. --- lib/tasks/db.rake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 68fb2d50f7..3170506fd1 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -575,3 +575,18 @@ task "db:status:json" do puts({ status: "ok" }.to_json) end end + +desc "Grow notification id column to a big int in case of overflow" +task "db:resize:notification_id" => :environment do + sql = <<~SQL + SELECT table_name, column_name FROM INFORMATION_SCHEMA.columns + WHERE (column_name like '%notification_id' OR column_name = 'id' and table_name = 'notifications') AND data_type = 'integer' + SQL + + DB + .query(sql) + .each do |row| + puts "Changing #{row.table_name}(#{row.column_name}) to a bigint" + DB.exec("ALTER table #{row.table_name} ALTER COLUMN #{row.column_name} TYPE BIGINT") + end +end