FIX: repair id sequence identity on summary table (#701)

1. Repairs the identity on the summary table, we migrated data without resetting it.
2. Adds an index into ai_summary table to match expected retrieval pattern
This commit is contained in:
Sam 2024-07-04 12:23:46 +10:00 committed by GitHub
parent 1320eed9b2
commit 38153608f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 0 deletions

View File

@ -26,3 +26,7 @@ end
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_ai_summaries_on_target_type_and_target_id (target_type,target_id)
#

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
class ResetIdentityOnAiSummary < ActiveRecord::Migration[7.0]
def up
add_index :ai_summaries, %i[target_type target_id]
# we need to reset identity since we moved this from the old summary_sections table
execute <<-SQL
DO $$
DECLARE
max_id integer;
BEGIN
SELECT MAX(id) INTO max_id FROM ai_summaries;
IF max_id IS NOT NULL THEN
PERFORM setval(pg_get_serial_sequence('ai_summaries', 'id'), max_id);
END IF;
END $$
SQL
end
def down
remove_index :ai_summaries, %i[target_type target_id]
end
end