Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions script/labels_cleanup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Label.find_each do |label|
downcase_name = label.name.downcase
dups = Label.where("name ilike ?", "%#{downcase_name}")
if dups.count > 1
# delete all except 1
the_one_true_label = dups.first
the_one_true_label.update(name: name.downcase)
dups.pop
dups.find_each do |dup|
shows = ScheduledShowLabel.where(label: dup)
shows.update_all label_id: the_one_true_label.id
tracks = TrackLabel.where(label: dup)
tracks.update_all label_id: the_one_true_label.id
end
dups.map(&:destroy)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to consolidate the tracks/shows with dup label before destroying the dup

end
end
9 changes: 9 additions & 0 deletions spec/models/label_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'rails_helper'

RSpec.describe Label, type: :model do
it 'always save the name as downcase' do
radio = FactoryBot.create :radio
label = Label.create name: 'FooOO', radio: radio
expect(label.name).to eq 'foooo'
end
end