discourse/db/migrate/20240606003822_reorder_flags.rb
Krzysztof Kotlarek 4b1e017722
FIX: move something else flag to the bottom (#27366)
The mistake was made when flags were moved to the database. The `notify_moderators` (something else) flag should be the last position on the list.

This commit contains 3 changes:
- update fixtures order;
- remove position and enable from fixtures (they can be overridden by admin and we don't want seed to restore them);
- migration to fix data if the order was not changed by admin.
2024-06-06 15:45:30 +10:00

26 lines
856 B
Ruby

# frozen_string_literal: true
class ReorderFlags < ActiveRecord::Migration[7.0]
def up
current_order = DB.query(<<~SQL)
SELECT name FROM flags
WHERE score_type IS FALSE
ORDER BY position ASC
SQL
if current_order.map(&:name) ==
%w[notify_user notify_moderators off_topic inappropriate spam illegal]
execute "UPDATE flags SET position = 0 WHERE name = 'notify_user'"
execute "UPDATE flags SET position = 1 WHERE name = 'off_topic'"
execute "UPDATE flags SET position = 2 WHERE name = 'inappropriate'"
execute "UPDATE flags SET position = 3 WHERE name = 'spam'"
execute "UPDATE flags SET position = 4 WHERE name = 'illegal'"
execute "UPDATE flags SET position = 5 WHERE name = 'notify_moderators'"
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end