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

Commit 1656bcf

Browse files
committed
Add unique index on summaries and dedup existing records
1 parent 175db51 commit 1656bcf

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
class UniqueAiSummaries < ActiveRecord::Migration[7.1]
3+
def up
4+
execute <<~SQL
5+
DELETE FROM ai_summaries ais1
6+
USING ai_summaries ais2
7+
WHERE ais1.id < ais2.id
8+
AND ais1.target_id = ais2.target_id
9+
AND ais1.target_type = ais2.target_type
10+
AND ais1.summary_type = ais2.summary_type
11+
SQL
12+
13+
add_index :ai_summaries, %i[target_id target_type summary_type], unique: true
14+
end
15+
16+
def down
17+
remove_index :ai_summaries, column: %i[target_id target_type summary_type]
18+
end
19+
end

0 commit comments

Comments
 (0)