about summary refs log tree commit diff
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-08-27 17:41:20 +0200
committerGitHub <noreply@github.com>2022-08-27 17:41:20 +0200
commitff19dad5a05dba689122b0427886c8375491571a (patch)
treeca4981c7f5b42eee352b2115ecd5cc11fc10ceaf
parent159b4edeef1ebdb70cc8d7d1316184252aef00a3 (diff)
Fix crash when adding a new filter (#18894)
Fixes #18742
-rw-r--r--db/post_migrate/20220729171123_fix_custom_filter_keywords_id_seq.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/db/post_migrate/20220729171123_fix_custom_filter_keywords_id_seq.rb b/db/post_migrate/20220729171123_fix_custom_filter_keywords_id_seq.rb
new file mode 100644
index 000000000..7ed34a3ef
--- /dev/null
+++ b/db/post_migrate/20220729171123_fix_custom_filter_keywords_id_seq.rb
@@ -0,0 +1,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