Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique index on uuid, message_thread_id to Messages #464

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/jobs/govbox/process_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ def perform(govbox_message)
processed_message = ::Message.where(type: [nil, 'Message']).where(uuid: govbox_message.message_id).joins(:thread).where(thread: { box_id: govbox_message.box.id }).take

ActiveRecord::Base.transaction do
destroy_associated_message_draft(govbox_message)

message = Govbox::Message.create_message_with_thread!(govbox_message)

destroy_associated_message_draft(govbox_message)
mark_delivery_notification_authorized(govbox_message)
mark_associated_delivery_notification_authorized(govbox_message)
collapse_referenced_outbox_message(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUniqueIndexOnUuidMessageThreadIdToMessages < ActiveRecord::Migration[7.0]
def up
add_index :messages, [:uuid, :message_thread_id], unique: true
end
end

3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/models/message_draft_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class MessageDraftTest < ActiveSupport::TestCase

test 'being_submitted! keeps DraftTag if drafts not in submission process present' do
message_draft = messages(:ssd_main_delivery_draft)

message_draft2 = message_draft.dup
message_draft2.update(uuid: SecureRandom.uuid)
message_draft2.save

message_draft.being_submitted!
Expand Down Expand Up @@ -109,6 +111,7 @@ class MessageDraftTest < ActiveSupport::TestCase
message_draft.being_submitted!

message_draft2 = message_draft.dup
message_draft2.update(uuid: SecureRandom.uuid)
message_draft2.save

message_thread = message_draft.thread
Expand Down
Loading