Skip to content

Instantly share code, notes, and snippets.

@sdepold
Created April 27, 2012 07:41
Show Gist options
  • Save sdepold/2507049 to your computer and use it in GitHub Desktop.
Save sdepold/2507049 to your computer and use it in GitHub Desktop.
category migration script cc @sdepold
puts "!! unique-ifying category names"
mk_unique = lambda{ |c| c.update_attribute(:name, c.name + rand(8**16).to_s(36)); print "." }
Category.all.each{ |c| mk_unique[c] if c.name.empty? || (Category.find_all_by_name(c.name).size > 1) }; nil
puts "\n\n!! migrating gettext keys"
mk_migrate = lambda{ |c, gk| gk.update_attribute(:accesskey, "category.#{c.name.to_slug}"); print "." }
Category.all.each{ |c| (gk = GettextKey.find_by_accesskey("category.#{c.id}")) ? mk_migrate[c, gk] : print("X") }; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment