Skip to content

Instantly share code, notes, and snippets.

@mitio
Created July 10, 2011 17:17
Show Gist options
  • Save mitio/1074717 to your computer and use it in GitHub Desktop.
Save mitio/1074717 to your computer and use it in GitHub Desktop.
"One-liner" to fix tab-delimited data, imported from PostgreSQL into SQLite
Dir['app/models/*.rb'].each do |m|
m = File.basename(m).split('.').first
m = m.camelcase.constantize
next unless m.respond_to?(:all)
m.all.each do |i|
m.columns.each do |c|
if [:string, :text].include?(c.type)
v = i.send(c.name)
i.send("#{c.name}=", v.gsub(/\\r\\n/, "\n")) if v && v.kind_of?(String)
end
end
i.save! if i.changed?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment