about summary refs log tree commit diff
path: root/db/post_migrate/20220729171123_fix_custom_filter_keywords_id_seq.rb
blob: eb437c86c5ab3705127faa6b5b2a19cc222151cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

class FixCustomFilterKeywordsIdSeq < ActiveRecord::Migration[6.1]
  disable_ddl_transaction!

  def up
    # 20220613110711 manually inserts items with set `id` in the database, but
    # we also need to bump the sequence number, otherwise
    safety_assured do
      execute <<-SQL.squish
        BEGIN;
        LOCK TABLE custom_filter_keywords IN EXCLUSIVE MODE;
        SELECT setval('custom_filter_keywords_id_seq'::regclass, id) FROM custom_filter_keywords ORDER BY id DESC LIMIT 1;
        COMMIT;
      SQL
    end
  end

  def down; end
end