Files
danbooru/script/fixes/092_normalize_artist_group_names.rb
evazion 02c9498860 artists: normalize group names.
Normalize artist group names following the same rules as artist other names.

This means artist group names now use underscores instead of spaces.
It also means extra space characters at the beginning and end of names
is stripped, and Unicode characters are normalized.

Fixes #4647, which was caused by users accidentally replacing group
names with a single space character when trying to remove a group.
2022-01-20 00:17:06 -06:00

18 lines
560 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "base"
with_confirmation do
CurrentUser.scoped(User.system) do
Artist.where.not(group_name: "").find_each do |artist|
artist.update!(group_name: artist.group_name) # forces normalization
if artist.saved_changes?
puts "id=#{artist.id} name=#{artist.name} oldgroup=`#{artist.group_name_before_last_save}` newgroup=`#{artist.group_name}`"
end
rescue ActiveRecord::RecordInvalid
puts "id=#{artist.id} name=#{artist.name} error=#{artist.errors.full_messages.join}"
end
end
end