FIX: Properly fix ai_summaries table sequence (#727)
* FIX: Properly fix ai_summaries table sequence Previous attempt at3815360
could fail due to a race introduced in1b0ba91
where summaries are migrated to core in a post_migrate erroneously.
This commit is contained in:
parent
d58913b227
commit
665637fbad
|
@ -0,0 +1,38 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class FixAiSummariesSequence < ActiveRecord::Migration[7.0]
|
||||||
|
def up
|
||||||
|
begin
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue