Skip to content

A platform for community discussion. Free, open, simple.

828 B
Raw Blame
# 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