discourse/plugins/discourse-ai/db/migrate/20240726164937_fix_ai_summaries_sequence.rb
Jarek Radosz fbb3bf3fe8
DEV: Enable Style/RedundantBegin rubocop rule (#40096)
(to be enabled in the shared config)

best reviewed with whitespace disabled
2026-05-19 18:44:54 +02:00

36 lines
828 B
Ruby
Vendored

# frozen_string_literal: true
class FixAiSummariesSequence < ActiveRecord::Migration[7.0]
def up
execute <<-SQL
SELECT
SETVAL (
'ai_summaries_id_seq',
(
SELECT
GREATEST (
(
SELECT
MAX(id)
FROM
summary_sections
),
(
SELECT
MAX(id)
FROM
ai_summaries
)
)
),
true
);
SQL
rescue ActiveRecord::StatementInvalid => e
# if the summary_table does not exist, we can ignore the error
end
def down
raise ActiveRecord::IrreversibleMigration
end
end