OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add migration to clean invalid custom_values
Oliver Günther151c38626a59
diff --git a/.rubocop.yml b/.rubocop.ymlindex 916ef699dd2..59093f84127 100644--- a/.rubocop.yml+++ b/.rubocop.yml@@ -228,6 +228,9 @@ WordArray:Style/FrozenStringLiteralComment:Enabled: false+Style/NumericLiterals:+ Enabled: false+# LintAmbiguousOperator:diff --git a/db/migrate/20190920102446_clean_custom_values.rb b/db/migrate/20190920102446_clean_custom_values.rbnew file mode 100644index 00000000000..5636cc0e83c--- /dev/null+++ b/db/migrate/20190920102446_clean_custom_values.rb@@ -0,0 +1,23 @@+class CleanCustomValues < ActiveRecord::Migration[5.2]+ def up+ invalid_cv = CustomValue+ .joins(:custom_field)+ .where("#{CustomField.table_name}.field_format = 'list'")+ .where.not(value: '')+ .where("value !~ '^[0-9]+$'")++ if invalid_cv.count > 0+ warn_string = "Replacing invalid list custom values:\n"+ invalid_cv.pluck(:customized_type, :customized_id, :value).each do |customized_type, customized_id, value|+ warn_string << "- #{customized_type} ##{customized_id}: Value was #{value.inspect}\n"+ end++ warn warn_string+ invalid_cv.update_column(:value, '')+ end+ end++ def down+ # This migration does not restore data+ end+end