mirror of
https://github.com/discourse/discourse.git
synced 2025-02-09 11:23:59 +08:00
![Bianca Nenciu](/assets/img/avatar_default.png)
* DEV: Migrate notifications#id to bigint (#28444) The `notifications.id` column is the most probable column to run out of values. This is because it is an `int` column that has only 2147483647 values and many notifications are generated on a regular basis in an active community. This commit migrates the column to `bigint`. These migrations do not use `ALTER TABLE ... COLUMN ... TYPE` in order to avoid the `ACCESS EXCLUSIVE` lock on the entire table. Instead, they create a new `bigint` column, copy the values to the new column and then sets the new column as primary key. Related columns (see `user_badges`, `shelved_notifications`) will be migrated in a follow-up commit. * DEV: Fix bigint notifications id migration to deal with public schema (#28538) Follow up to799a45a291
* DEV: Migrate shelved_notifications#notification_id to bigint (#28549) DEV: Migrate shelved_notifications#notification_id to bigint The `notifications.id` has been migrated to `bigint` in previous commit799a45a291
. * DEV: Fix annotations (#28569) Follow-up toec8ba5a0b9
* DEV: Migrate user_badges#notification_id to bigint (#28546) The `notifications.id` has been migrated to bigint in previous commit799a45a291
. This commit migrates one of the related columns, `user_badges.notification_id`, to `bigint`. * DEV: Migrate `User#seen_notification_id` to `bigint` (#28572) `Notification#id` was migrated to `bigint` in799a45a291
* DEV: Migrate `Chat::NotificationMention#notification_id` to `bigint` (#28571) `Notification#id` was migrated to `bigint` in799a45a291
--------- Co-authored-by: Alan Guo Xiang Tan <gxtan1990@gmail.com>
34 lines
1.0 KiB
Ruby
34 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class DropOldNotificationIdIndexes < ActiveRecord::Migration[7.0]
|
|
disable_ddl_transaction!
|
|
|
|
def up
|
|
# Drop old indexes
|
|
results =
|
|
execute(
|
|
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'notifications' AND indexdef SIMILAR TO '%\\mold_id\\M%'",
|
|
)
|
|
results.each do |res|
|
|
indexname, indexdef = res["indexname"], res["indexdef"]
|
|
execute "DROP INDEX #{Rails.env.test? ? "" : "CONCURRENTLY"} IF EXISTS #{indexname}"
|
|
end
|
|
|
|
# Remove `_bigint` suffix from indexes
|
|
results =
|
|
execute(
|
|
"SELECT indexname, indexdef FROM pg_indexes WHERE tablename = 'notifications' AND indexdef SIMILAR TO '%\\mid\\M%' AND schemaname = 'public'",
|
|
)
|
|
results.each do |res|
|
|
indexname, indexdef = res["indexname"], res["indexdef"]
|
|
if indexname.include?("_bigint")
|
|
execute "ALTER INDEX #{indexname} RENAME TO #{indexname.gsub(/_bigint$/, "")}"
|
|
end
|
|
end
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|