OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/db/migrate/20210214205545_replace_inva...

23 lines
712 B

class ReplaceInvalidPrincipalReferences < ActiveRecord::Migration[6.1]
def up
DeletedUser.reset_column_information
deleted_user_id = DeletedUser.first.id
say "Replacing invalid custom value user references"
CustomValue
.joins(:custom_field)
.where("#{CustomField.table_name}.field_format" => 'user')
.where("value NOT IN (SELECT id::text FROM users)")
.update_all(value: deleted_user_id)
say "Replacing invalid responsible user references in work packages"
WorkPackage
.where("responsible_id NOT IN (SELECT id FROM users)")
.update_all(responsible_id: deleted_user_id)
end
def down
# Nothing to do, as only invalid data is fixed
end
end