diff --git a/app/models/ai_summary.rb b/app/models/ai_summary.rb index 027dd5ce..f947dc0d 100644 --- a/app/models/ai_summary.rb +++ b/app/models/ai_summary.rb @@ -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) +# diff --git a/db/migrate/20240704020102_reset_identity_on_ai_summary.rb b/db/migrate/20240704020102_reset_identity_on_ai_summary.rb new file mode 100644 index 00000000..5c87763d --- /dev/null +++ b/db/migrate/20240704020102_reset_identity_on_ai_summary.rb @@ -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