fix invalid domain block severities

This commit fixes any invalid domain block severities by setting them to
2 if they are bigger than 2 or 0 if they are smaller than 0.
This ensures that the domain block severities are always within the valid
range of 0 to 2.
This commit is contained in:
Wolfgang Fournès 2024-02-20 08:48:52 +00:00 committed by hendrixfan
parent 0b66433c08
commit 64d2a6eba0
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
# frozen_string_literal: true
class FixInvalidDomainBlockSeverities < ActiveRecord::Migration[7.1]
disable_ddl_transaction!
def up
safety_assured do
execute <<~SQL.squish
UPDATE domain_blocks
SET severity = CASE WHEN severity > 2 THEN 2 WHEN severity < 0 THEN 0 END
WHERE severity > 2 OR severity < 0 RETURNING id;
SQL
end
end
def down; end
end