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
Remove all unused keys from the settings json
Oliver Günther614de339f014
diff --git a/db/migrate/20210902201126_cleanup_user_preferences.rb b/db/migrate/20210902201126_cleanup_user_preferences.rbindex 2a00fb5ae46..c5f32e9aba6 100644--- a/db/migrate/20210902201126_cleanup_user_preferences.rb+++ b/db/migrate/20210902201126_cleanup_user_preferences.rb@@ -12,9 +12,18 @@ class CleanupUserPreferences < ActiveRecord::Migration[6.1]WHERE settings ->> 'warn_on_leaving_unsaved' = '0'SQL+ # Remove all other keys from the user preferences+ object_map = UserPreferences::Schema.properties.map { |key| "'#{key}', settings->'#{key}'" }.join(", ")execute <<~SQL.squish+ WITH subquery AS (+ SELECT id,+ jsonb_strip_nulls(jsonb_build_object(#{object_map})) as stripped_settings+ FROM user_preferences+ )UPDATE user_preferences- SET settings = settings - 'no_self_notified'+ SET settings = subquery.stripped_settings+ FROM subquery+ WHERE user_preferences.id = subquery.idSQLend