DEV: Set bigint sequences to start at MAX_INT (#28961)

This helps uncover issues with bigint columns that are joined with int
columns. It also introduces a temporary API for plugins to migrate int
columns to bigint in test environment to make tests pass.
This commit is contained in:
Bianca Nenciu 2024-10-10 19:28:45 +03:00 committed by GitHub
parent dd34f1927b
commit 33a4ab13b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 6 deletions

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class AlterAutomationIdsToBigint < ActiveRecord::Migration[7.1]
def up
change_column :discourse_automation_fields, :automation_id, :bigint
change_column :discourse_automation_pending_automations, :automation_id, :bigint
change_column :discourse_automation_pending_pms, :automation_id, :bigint
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -94,8 +94,8 @@ module Chat
DB.exec <<~SQL
CREATE TEMPORARY TABLE moved_chat_messages (
old_chat_message_id INTEGER,
new_chat_message_id INTEGER
old_chat_message_id BIGINT,
new_chat_message_id BIGINT
) ON COMMIT DROP;
CREATE INDEX moved_chat_messages_old_chat_message_id ON moved_chat_messages(old_chat_message_id);

View File

@ -139,4 +139,24 @@ RSpec.configure do |config|
# Or a very large value, if you do want to truncate at some point
c.max_formatted_output_length = nil
end
config.before(:suite) do
migrate_column_to_bigint(Chat::Channel, :chatable_id)
migrate_column_to_bigint(Chat::ChannelArchive, :chat_channel_id)
migrate_column_to_bigint(Chat::DirectMessageUser, :direct_message_channel_id)
migrate_column_to_bigint(Chat::Draft, :chat_channel_id)
migrate_column_to_bigint(Chat::IncomingWebhook, :chat_channel_id)
migrate_column_to_bigint(Chat::Mention, :chat_message_id)
migrate_column_to_bigint(Chat::MentionNotification, :chat_mention_id)
migrate_column_to_bigint(Chat::MentionNotification, :notification_id)
migrate_column_to_bigint(Chat::Message, :chat_channel_id)
migrate_column_to_bigint(Chat::Message, :in_reply_to_id)
migrate_column_to_bigint(Chat::MessageReaction, :chat_message_id)
migrate_column_to_bigint(Chat::MessageRevision, :chat_message_id)
migrate_column_to_bigint(Chat::UserChatChannelMembership, :chat_channel_id)
migrate_column_to_bigint(Chat::UserChatChannelMembership, :last_read_message_id)
migrate_column_to_bigint(Chat::UserChatChannelMembership, :last_unread_mention_when_emailed_id)
migrate_column_to_bigint(Chat::WebhookEvent, :chat_message_id)
migrate_column_to_bigint(Chat::WebhookEvent, :incoming_chat_webhook_id)
end
end

View File

@ -466,12 +466,32 @@ RSpec.configure do |config|
Capybara::Selenium::Driver.new(app, **mobile_driver_options)
end
if ENV["ELEVATED_UPLOADS_ID"]
DB.exec "SELECT setval('uploads_id_seq', 10000)"
else
DB.exec "SELECT setval('uploads_id_seq', 1)"
migrate_column_to_bigint(AllowedPmUser, :allowed_pm_user_id)
migrate_column_to_bigint(Bookmark, :bookmarkable_id)
migrate_column_to_bigint(IgnoredUser, :ignored_user_id)
migrate_column_to_bigint(PostAction, :post_action_type_id)
migrate_column_to_bigint(Reviewable, :target_id)
migrate_column_to_bigint(ReviewableHistory, :reviewable_id)
migrate_column_to_bigint(ReviewableScore, :reviewable_id)
migrate_column_to_bigint(ReviewableScore, :reviewable_score_type)
migrate_column_to_bigint(SidebarSectionLink, :linkable_id)
migrate_column_to_bigint(SidebarSectionLink, :sidebar_section_id)
migrate_column_to_bigint(User, :last_seen_reviewable_id)
migrate_column_to_bigint(User, :required_fields_version)
$columns_to_migrate_to_bigint.each do |model, column|
if model.is_a?(String)
DB.exec("ALTER TABLE #{model} ALTER #{column} TYPE bigint")
else
DB.exec("ALTER TABLE #{model.table_name} ALTER #{column} TYPE bigint")
model.reset_column_information
end
end
DB
.query("SELECT sequence_name FROM information_schema.sequences WHERE data_type = 'bigint'")
.each { |row| DB.exec "SELECT setval('#{row.sequence_name}', #{2**32})" }
# Prevents 500 errors for site setting URLs pointing to test.localhost in system specs.
SiteIconManager.clear_cache!
end
@ -1018,6 +1038,10 @@ def apply_base_chrome_options(options)
end
end
def migrate_column_to_bigint(model, column)
($columns_to_migrate_to_bigint ||= []) << [model, column]
end
class SpecSecureRandom
class << self
attr_accessor :value