Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 294c364

Browse files
authored
DEV: Fix mismatched column types (#868)
The primary key is usually a bigint column, but the foreign key columns are usually of integer type. This can lead to issues when joining these columns due to mismatched types and different value ranges. This was using a temporary plugin / test API to make tests pass, but it is safe to alter "ai_document_fragment_embeddings" and "rag_document_fragments" tables because they usually have less than 1M rows and migration is going to be fast. Depending on the size of the community, "classification_results" table may have more than 1M rows and the migration will lock the table for a longer time. However, classification runs in background jobs and they will be automatically retried if they fail due to the lock, which makes it acceptable.
1 parent c479b17 commit 294c364

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class AlterAiIdsToBigint < ActiveRecord::Migration[7.1]
4+
def up
5+
change_column :ai_document_fragment_embeddings, :rag_document_fragment_id, :bigint
6+
change_column :classification_results, :target_id, :bigint
7+
change_column :rag_document_fragments, :target_id, :bigint
8+
end
9+
10+
def down
11+
raise ActiveRecord::IrreversibleMigration
12+
end
13+
end

spec/plugin_helper.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,4 @@ def assign_fake_provider_to(setting_name)
1717
end
1818
end
1919

20-
RSpec.configure do |config|
21-
config.include DiscourseAi::ChatBotHelper
22-
23-
config.before(:suite) do
24-
if defined?(migrate_column_to_bigint)
25-
migrate_column_to_bigint(RagDocumentFragment, :target_id)
26-
migrate_column_to_bigint("ai_document_fragment_embeddings", "rag_document_fragment_id")
27-
migrate_column_to_bigint(ClassificationResult, :target_id)
28-
end
29-
end
30-
end
20+
RSpec.configure { |config| config.include DiscourseAi::ChatBotHelper }

0 commit comments

Comments
 (0)