explicitly check both names and slugs for duplication in data migration

increase timestamp on migration to allow recovery of previously-broken nightly installs (i.e. mine)
This commit is contained in:
James Smith committed 2023-06-29 09:02:26 +01:00
1 parent 0a4ab3129d
commit ecbb208b5a
3 files changed
+24 -21

No files matched your search

@@ -1,20 +0,0 @@
# frozen_string_literal: true
class MakeNamesUnique < ActiveRecord::Migration[7.0]
def up
[Creator, Collection].each do |klass|
klass.all.group_by { |x| x.name.downcase }.each_pair do |name, items|
if items.count > 1
items.slice(1..-1).each do |c|
c.name = "#{c.name} #{SecureRandom.hex(4)}"
c.save!
end
end
end
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
@@ -0,0 +1,23 @@
# frozen_string_literal: true
class MakeNamesUnique < ActiveRecord::Migration[7.0]
def up
attributes = [:name, :slug]
[Creator, Collection].each do |klass|
attributes.each do |attr|
klass.all.group_by { |x| x.send(attr).downcase }.each_pair do |n, items|
if items.count > 1
items.slice(1..-1).each do |c|
c.name = "#{c.name} #{SecureRandom.hex(4)}"
c.save!
end
end
end
end
end
end
def down
raise ActiveRecord::IrreversibleMigration
end
end
+1 -1
View File
@@ -1 +1 @@
DataMigrate::Data.define(version: 20230628194943)
DataMigrate::Data.define(version: 20230628194944)