Skip to content

Commit

Permalink
Add tenant reference to MessageThreadMergeIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Sep 19, 2023
1 parent 0edf3eb commit f620e94
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/box/message_threads_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def find_or_create_by_merge_uuid!(folder:, merge_uuid:, title:, delivered_at:)
delivered_at: delivered_at,
last_message_delivered_at: delivered_at
)
thread.merge_identifiers.build(uuid: merge_uuid)
thread.merge_identifiers.build(uuid: merge_uuid, tenant: folder.tenant)
end

thread.save!
Expand Down
2 changes: 2 additions & 0 deletions app/models/message_thread_merge_identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
#
# id :integer not null, primary key
# message_thread_id :integer not null
# tenant_id :integer not null
# uuid :uuid not null
# created_at :datetime not null
# updated_at :datetime not null

class MessageThreadMergeIdentifier < ApplicationRecord
belongs_to :message_thread
belongs_to :tenant
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddTenantIdToMessageThreadMergeIdentifiers < ActiveRecord::Migration[7.0]
def up
add_reference :message_thread_merge_identifiers, :tenant, foreign_key: true

MessageThreadMergeIdentifier.find_each { |merge_identifier| merge_identifier.update(tenant: merge_identifier.message_thread.folder.tenant) }

change_column :message_thread_merge_identifiers, :tenant_id, :bigint, null: false, foreign_key: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class UpdateMessageThreadMergeIdentifiersUniqueConstraint < ActiveRecord::Migration[7.0]
def change
remove_index :message_thread_merge_identifiers, :uuid, unique: true
add_index :message_thread_merge_identifiers, [:uuid, :tenant_id], unique: true
end
end
7 changes: 5 additions & 2 deletions 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/fixtures/message_thread_merge_identifiers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
one:
message_thread: one
uuid: <%= SecureRandom.uuid %>
tenant: solver

two:
message_thread: one
uuid: <%= SecureRandom.uuid %>
tenant: solver

three:
message_thread: two
uuid: <%= SecureRandom.uuid %>
tenant: solver

0 comments on commit f620e94

Please sign in to comment.