-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix migrations - consider box when selecting messages & add dependent…
… option to message relations
- Loading branch information
1 parent
48bc76b
commit 60d610e
Showing
6 changed files
with
46 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
db/migrate/20231020095255_change_messages_collapsed_attribute.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class ChangeMessagesCollapsedAttribute < ActiveRecord::Migration[7.0] | ||
def change | ||
Message.order(:delivered_at).find_each do |message| | ||
if message.is_a?(MessageDraft) | ||
message.update(collapsed: false) | ||
next | ||
end | ||
|
||
govbox_message = Govbox::Message.where(message_id: message.uuid) | ||
.joins(folder: :box).where(folders: { boxes: { id: message.thread.box.id } }).take | ||
|
||
message.update(collapsed: govbox_message.collapsed?) | ||
|
||
delivery_notification_govbox_message = Govbox::Message.where("payload -> 'delivery_notification' -> 'consignment' ->> 'message_id' = ?", govbox_message.message_id) | ||
.joins(folder: :box).where(folders: { boxes: { id: govbox_message.box.id } }).take | ||
|
||
if delivery_notification_govbox_message | ||
delivery_notification_message = ::Message.where(uuid: delivery_notification_govbox_message.message_id) | ||
.joins(thread: :folder).where(folders: { box_id: govbox_message.box.id }).take | ||
delivery_notification_message.update(collapsed: true) | ||
end | ||
end | ||
|
||
change_column :messages, :collapsed, :boolean, null: false, default: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class FixMessageRelations < ActiveRecord::Migration[7.0] | ||
def up | ||
MessageRelation.destroy_all | ||
|
||
Message.find_each do |message| | ||
main_message = Message.where(uuid: message.metadata["reference_id"]).joins(thread: :folder).where(folders: { box_id: message.thread.box.id }).take | ||
|
||
main_message.message_relations.find_or_create_by!( | ||
related_message: message, | ||
) if main_message | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.