Skip to content

Instantly share code, notes, and snippets.

@timharding
Created August 18, 2016 10:39
Show Gist options
  • Save timharding/bfebb9a6d95a9e837b1463d4a1a10d4e to your computer and use it in GitHub Desktop.
Save timharding/bfebb9a6d95a9e837b1463d4a1a10d4e to your computer and use it in GitHub Desktop.
Rails.application.eager_load! if Rails.env.development?
ActiveRecord::Base.descendants.each do |d|
puts d.table_name
d.columns_hash.each do |f, t|
if t.type == :string || t.type == :text
puts "\t#{f} #{t.type}"
queries = []
queries << "#{f} = replace(#{f}, '“', '“')"
queries << "#{f} = replace(#{f}, '’', '’')"
queries << "#{f} = replace(#{f}, '‘', '‘')"
queries << "#{f} = replace(#{f}, '—', '–')"
queries << "#{f} = replace(#{f}, '–', '—')"
queries << "#{f} = replace(#{f}, '•', '-')"
queries << "#{f} = replace(#{f}, '…', '…')"
queries << "#{f} = replace(#{f}, '”', '”')"
queries << "#{f} = replace(#{f}, '―', '—')"
queries << "#{f} = replace(#{f}, '£', '£')"
queries << "#{f} = replace(#{f}, 'é', 'é')"
queries << "#{f} = replace(#{f}, 'ö', 'ö')"
queries.each do |q|
d.update_all(q)
end
end
end
end;nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment