aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/raw_email.rb
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-10-30 19:00:18 +0000
committerFrancis Irving <francis@mysociety.org>2009-10-30 19:00:18 +0000
commitf860c6acd6075dca17200ed75b223842e932ae43 (patch)
treed92d70edc5ce9b12fbbb30ebd2f35ccb4e404031 /app/models/raw_email.rb
parentb8c3a21fe41d0916dcce190fbce1fd6183d4d5e5 (diff)
Migrate to using a binary database field for storing raw emails, rather than text.
Does it gradually, so existing column is left alone to speed things up.
Diffstat (limited to 'app/models/raw_email.rb')
-rw-r--r--app/models/raw_email.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb
index 7e7db2b62..921c04034 100644
--- a/app/models/raw_email.rb
+++ b/app/models/raw_email.rb
@@ -19,6 +19,31 @@ class RawEmail < ActiveRecord::Base
# deliberately don't strip_attributes, so keeps raw email properly
has_one :incoming_message
+
+
+ # We keep the old data_text field (which is of type text) for backwards
+ # compatibility. We use the new data_binary field because only it works
+ # properly in recent versions of PostgreSQL (get seg faults escaping
+ # some binary strings).
+
+ def data=(d)
+ write_attribute(:data_binary, d)
+ end
+
+ def data
+ d = read_attribute(:data_binary)
+ if !d.nil?
+ return d
+ end
+
+ d = read_attribute(:data_text)
+ if !d.nil?
+ return d
+ end
+
+ raise "internal error, double nil value in RawEmail"
+ end
+
end