FIX: do not allow tag with name 'none' (#9867)

https://meta.discourse.org/t/none-tag-is-uneditable/152003
This commit is contained in:
Arpit Jalan
2020-05-26 08:15:45 +05:30
committed by GitHub
parent 878f06f1fe
commit 5462fe9462
3 changed files with 32 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
# frozen_string_literal: true
class RemoveNoneTags < ActiveRecord::Migration[6.0]
def up
none_tag_id = DB.query_single("SELECT id FROM tags WHERE lower(name) = 'none'").first
if none_tag_id.present?
[:tag_users, :topic_tags, :category_tag_stats, :category_tags, :tag_group_memberships].each do |table_name|
execute "DELETE FROM #{table_name} WHERE tag_id = #{none_tag_id}"
end
execute "DELETE FROM tags WHERE id = #{none_tag_id} OR target_tag_id = #{none_tag_id}"
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end