mirror of
https://github.com/manyfold3d/manyfold.git
synced 2026-10-22 03:32:18 -05:00
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:
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
@@ -1 +1 @@
|
||||
DataMigrate::Data.define(version: 20230628194943)
|
||||
DataMigrate::Data.define(version: 20230628194944)
|
||||
Reference in new issue
Block a user