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:
parent
1320eed9b2
commit
38153608f8
|
@ -26,3 +26,7 @@ end
|
||||||
# created_at :datetime not null
|
# created_at :datetime not null
|
||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
#
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_ai_summaries_on_target_type_and_target_id (target_type,target_id)
|
||||||
|
#
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue