diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/022_create_info_request_events.rb | 38 | ||||
-rw-r--r-- | db/migrate/028_give_incoming_messages_events.rb | 19 | ||||
-rw-r--r-- | db/schema.rb | 2 |
3 files changed, 39 insertions, 20 deletions
diff --git a/db/migrate/022_create_info_request_events.rb b/db/migrate/022_create_info_request_events.rb index fe7450773..858444298 100644 --- a/db/migrate/022_create_info_request_events.rb +++ b/db/migrate/022_create_info_request_events.rb @@ -1,24 +1,24 @@ class CreateInfoRequestEvents < ActiveRecord::Migration - def self.up - create_table :info_request_events do |t| - t.column "info_request_id", :integer - t.column :event_type, :text - t.column :params_yaml, :text - t.column :created_at, :datetime - end + def self.up + create_table :info_request_events do |t| + t.column "info_request_id", :integer + t.column :event_type, :text + t.column :params_yaml, :text + t.column :created_at, :datetime + end - # Create the missing events for requests already sent - InfoRequest.find(:all).each do |info_request| - info_request_event = InfoRequestEvent.new - info_request_event.event_type = 'sent' - info_request_event.params = { :email => info_request.recipient_email, :outgoing_message_id => info_request.outgoing_messages[0].id } - info_request_event.info_request = info_request - info_request_event.created_at = info_request.outgoing_messages[0].sent_at - info_request_event.save! + # Create the missing events for requests already sent + InfoRequest.find(:all).each do |info_request| + info_request_event = InfoRequestEvent.new + info_request_event.event_type = 'sent' + info_request_event.params = { :email => info_request.recipient_email, :outgoing_message_id => info_request.outgoing_messages[0].id } + info_request_event.info_request = info_request + info_request_event.created_at = info_request.outgoing_messages[0].sent_at + info_request_event.save! + end end - end - def self.down - drop_table :info_request_events - end + def self.down + drop_table :info_request_events + end end diff --git a/db/migrate/028_give_incoming_messages_events.rb b/db/migrate/028_give_incoming_messages_events.rb new file mode 100644 index 000000000..270c532a0 --- /dev/null +++ b/db/migrate/028_give_incoming_messages_events.rb @@ -0,0 +1,19 @@ +class GiveIncomingMessagesEvents < ActiveRecord::Migration + def self.up + ActiveRecord::Base.transaction do + IncomingMessage.find(:all).each do |incoming_message| + info_request_event = InfoRequestEvent.new + info_request_event.event_type = 'response' + info_request_event.params = { :incoming_message_id => incoming_message.id } + info_request_event.info_request = incoming_message.info_request + info_request_event.created_at = incoming_message.created_at + info_request_event.save! + end + end + end + + def self.down + InfoRequestEvent.delete_all "event_type = 'response'" + end +end + diff --git a/db/schema.rb b/db/schema.rb index 057a239b9..79fdc7e86 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 => 27) do +ActiveRecord::Schema.define(:version => 28) do create_table "incoming_messages", :force => true do |t| t.integer "info_request_id", :null => false |