aboutsummaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
Diffstat (limited to 'db')
-rw-r--r--db/migrate/067_factor_out_raw_email.rb38
-rw-r--r--db/schema.rb8
2 files changed, 44 insertions, 2 deletions
diff --git a/db/migrate/067_factor_out_raw_email.rb b/db/migrate/067_factor_out_raw_email.rb
new file mode 100644
index 000000000..be4153938
--- /dev/null
+++ b/db/migrate/067_factor_out_raw_email.rb
@@ -0,0 +1,38 @@
+class FactorOutRawEmail < ActiveRecord::Migration
+ def self.up
+ create_table :raw_emails do |t|
+ t.column :data, :text, :null => false
+ end
+
+ add_column :incoming_messages, :raw_email_id, :integer, :null => true
+ change_column :incoming_messages, :raw_data, :text, :null => true
+
+ if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
+ execute "ALTER TABLE incoming_messages ADD CONSTRAINT fk_incoming_messages_raw_email FOREIGN KEY (raw_email_id) REFERENCES raw_emails(id)"
+ end
+
+ batch_size = 10
+ 0.step(IncomingMessage.count, batch_size) do |i|
+ IncomingMessage.find(:all, :limit => batch_size, :offset => i, :order => :id).each do |incoming_message|
+ if incoming_message.raw_email_id.nil?
+ STDERR.puts "doing incoming_message id " + incoming_message.id.to_s
+ ActiveRecord::Base.transaction do
+ raw_email = RawEmail.new
+ raw_email.data = incoming_message.raw_data
+ incoming_message.raw_email = raw_email
+ incoming_message.raw_data = nil
+ raw_email.save!
+ incoming_message.save!
+ end
+ end
+ end
+ end
+
+ change_column :incoming_messages, :raw_email_id, :integer, :null => false
+ remove_column :incoming_messages, :raw_data
+ end
+
+ def self.down
+ raise "down migration not implemented"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 496df6f0c..bce1b4d10 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 66) do
+ActiveRecord::Schema.define(:version => 67) do
create_table "acts_as_xapian_jobs", :force => true do |t|
t.string "model", :null => false
@@ -31,11 +31,11 @@ ActiveRecord::Schema.define(:version => 66) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
- t.text "raw_data", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "cached_attachment_text"
t.text "cached_main_body_text"
+ t.integer "raw_email_id", :null => false
end
create_table "info_request_events", :force => true do |t|
@@ -139,6 +139,10 @@ ActiveRecord::Schema.define(:version => 66) do
t.text "notes"
end
+ create_table "raw_emails", :force => true do |t|
+ t.binary "data", :null => false
+ end
+
create_table "track_things", :force => true do |t|
t.integer "tracking_user_id", :null => false
t.string "track_query", :null => false