Created
July 10, 2011 17:17
-
-
Save mitio/1074717 to your computer and use it in GitHub Desktop.
"One-liner" to fix tab-delimited data, imported from PostgreSQL into SQLite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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