diff options
author | Marius Balteanu <marius.balteanu@zitec.com> | 2021-09-06 18:30:04 +0000 |
---|---|---|
committer | Marius Balteanu <marius.balteanu@zitec.com> | 2021-09-06 18:30:04 +0000 |
commit | 4378b7e1b47311aa1f7cf4992321dc0cbd9e5830 (patch) | |
tree | 11dd49df71096c6a31e79da4755fa056cfbf0a03 /db | |
parent | 2b1d88fa599653442e7c77d0493064ac35f1ec52 (diff) | |
download | redmine-4378b7e1b47311aa1f7cf4992321dc0cbd9e5830.tar.gz redmine-4378b7e1b47311aa1f7cf4992321dc0cbd9e5830.zip |
Remove references to deleted user from "user"-Format CustomFields when destroying an user (#32977).
Patch by Jens Krämer.
git-svn-id: http://svn.redmine.org/redmine/trunk@21207 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20210801211024_remove_orphaned_user_custom_values.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/db/migrate/20210801211024_remove_orphaned_user_custom_values.rb b/db/migrate/20210801211024_remove_orphaned_user_custom_values.rb new file mode 100644 index 000000000..446ef7f10 --- /dev/null +++ b/db/migrate/20210801211024_remove_orphaned_user_custom_values.rb @@ -0,0 +1,12 @@ +class RemoveOrphanedUserCustomValues < ActiveRecord::Migration[6.1] + def up + user_custom_field_ids = CustomField.where(field_format: 'user').pluck(:id) + if user_custom_field_ids.any? + user_ids = Principal.pluck(:id) + CustomValue. + where(custom_field_id: user_custom_field_ids). + where.not(value: [nil, ''] + user_ids). + delete_all + end + end +end |