Skip to content

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

Fix the way in which the conditions are queried and key is set

Aaron Contreras16c20eea4645
diff --git a/db/migrate/20240909151818_migrate_legacy_default_theme_to_light_theme.rb b/db/migrate/20240909151818_migrate_legacy_default_theme_to_light_theme.rb
index 96bc3606af2..5dd23543215 100644
--- a/db/migrate/20240909151818_migrate_legacy_default_theme_to_light_theme.rb
+++ b/db/migrate/20240909151818_migrate_legacy_default_theme_to_light_theme.rb
@@ -29,29 +29,29 @@
#++
class MigrateLegacyDefaultThemeToLightTheme < ActiveRecord::Migration[7.1]
- class MigrationUserPreference < ActiveRecord::Base
- self.table_name = "user_preferences"
- end
-
# Migrate legacy `default` theme to `light` theme
#
# Moving from:
# {
# "settings": {
- # "theme": "default"
+ # "theme": "default",
+ # "foo": "bar"
# }
# }
#
# To:
# {
# "settings": {
- # "theme": "light" # current default theme
+ # "theme": "light", # current default theme
+ # "foo": "bar"
# }
# }
def up
- MigrationUserPreference
- .where(settings: { theme: "default" })
- .update_all(settings: { theme: "light" })
+ execute <<-SQL.squish
+ UPDATE user_preferences
+ SET settings = jsonb_set(settings, '{theme}', '"light"')
+ WHERE settings->>'theme' = 'default';
+ SQL
end
# no-op
diff --git a/spec/migrations/migrate_legacy_default_theme_to_light_theme_spec.rb b/spec/migrations/migrate_legacy_default_theme_to_light_theme_spec.rb
index 5deb6f9479a..7cac0fd2cf9 100644
--- a/spec/migrations/migrate_legacy_default_theme_to_light_theme_spec.rb
+++ b/spec/migrations/migrate_legacy_default_theme_to_light_theme_spec.rb
@@ -35,10 +35,12 @@ RSpec.describe MigrateLegacyDefaultThemeToLightTheme, type: :model do
# Silencing migration logs, since we are not interested in that during testing
subject(:run_migration) { ActiveRecord::Migration.suppress_messages { described_class.new.up } }
- shared_let(:user_with_default_theme) { create(:user, preferences: { settings: { theme: "default" } }) }
- shared_let(:user_with_light_theme) { create(:user, preferences: { settings: { theme: "light" } }) }
- shared_let(:user_with_light_high_contrast_theme) { create(:user, preferences: { settings: { theme: "light_high_contrast" } }) }
- shared_let(:user_with_dark_theme) { create(:user, preferences: { settings: { theme: "dark" } }) }
+ shared_let(:user_with_default_theme) { create(:user, preferences: { settings: { theme: "default", foo: "bar" } }) }
+ shared_let(:user_with_light_theme) { create(:user, preferences: { settings: { theme: "light", foo: "bar" } }) }
+ shared_let(:user_with_light_high_contrast_theme) do
+ create(:user, preferences: { settings: { theme: "light_high_contrast", foo: "bar" } })
+ end
+ shared_let(:user_with_dark_theme) { create(:user, preferences: { settings: { theme: "dark", foo: "bar" } }) }
it "sets the theme to light for users with the 'default' theme" do
expect { run_migration }