From 98aee048f29518e3380c208234b38f9ae2e6afd0 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 20 Jan 2022 16:01:31 -0600 Subject: [PATCH] artists: fix old artists with invalid names. There are a lot of old artist entries with Japanese names. These names are now invalid and these artist entries can't be edited because they fail validation checks. Add a fix script to delete all artist entries with non-ASCII names, and rename them to `artist_1234`. --- script/fixes/093_fix_invalid_artist_names.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 script/fixes/093_fix_invalid_artist_names.rb diff --git a/script/fixes/093_fix_invalid_artist_names.rb b/script/fixes/093_fix_invalid_artist_names.rb new file mode 100755 index 000000000..6e0aeb183 --- /dev/null +++ b/script/fixes/093_fix_invalid_artist_names.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +require_relative "base" + +with_confirmation do + CurrentUser.scoped(User.system) do + Artist.where("name ~ '[^[:ascii:]]'").find_each do |artist| + artist.other_names += [artist.name] + artist.name = "artist_#{artist.id}" + artist.is_deleted = true + artist.save! + + if artist.saved_changes? + puts "id=#{artist.id} oldname=#{artist.name_before_last_save} newname=`#{artist.name}` other_names=#{artist.other_names}" + end + rescue ActiveRecord::RecordInvalid + puts "id=#{artist.id} name=#{artist.name} error=#{artist.errors.full_messages.join}" + end + end +end