forked from revoltchat/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: Add uniqueness index inside taskbar table.
Co-authored-by: Mantas Masalskis <[email protected]> Co-authored-by: Dominik Klein <[email protected]>
- Loading branch information
1 parent
8ee1546
commit 40d2086
Showing
6 changed files
with
43 additions
and
60 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class TaskbarAddUniquenessIndex < ActiveRecord::Migration[7.1] | ||
def change | ||
return if !Setting.exists?(name: 'system_init_done') | ||
|
||
duplicates = Taskbar.select(:user_id, :app, :key).group(:user_id, :app, :key).having('COUNT(*) > 1').reorder(nil) | ||
|
||
if duplicates.exists? | ||
Taskbar | ||
.where( | ||
user_id: duplicates.pluck(:user_id), | ||
app: duplicates.pluck(:app), | ||
key: duplicates.pluck(:key) | ||
) | ||
.group_by { |taskbar| [taskbar.user_id, taskbar.app, taskbar.key] } | ||
.each_value do |records| | ||
newest_record = records.max_by(&:last_contact) | ||
|
||
records.reject { |record| record == newest_record }.each(&:destroy) | ||
end | ||
end | ||
|
||
add_index :taskbars, %i[user_id key app], unique: true | ||
|
||
Taskbar.reset_column_information | ||
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
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