Skip to content

A platform for community discussion. Free, open, simple.

DEV: Rename discourse_rewind_disabled column to discourse_rewind_enabled (#36961)

Régis Hanol22e06e715126
diff --git a/plugins/discourse-rewind/db/migrate/20260105171115_rename_discourse_rewind_disabled_to_enabled.rb b/plugins/discourse-rewind/db/migrate/20260105171115_rename_discourse_rewind_disabled_to_enabled.rb
new file mode 100644
index 00000000000..f0d3fa36b0e
--- /dev/null
+++ b/plugins/discourse-rewind/db/migrate/20260105171115_rename_discourse_rewind_disabled_to_enabled.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class RenameDiscourseRewindDisabledToEnabled < ActiveRecord::Migration[7.2]
+ def up
+ add_column :user_options, :discourse_rewind_enabled, :boolean, default: true, null: false
+
+ execute <<~SQL
+ UPDATE user_options
+ SET discourse_rewind_enabled = NOT discourse_rewind_disabled
+ SQL
+
+ change_column_default :user_options, :discourse_rewind_disabled, nil
+
+ Migration::ColumnDropper.mark_readonly(:user_options, :discourse_rewind_disabled)
+ end
+
+ def down
+ Migration::ColumnDropper.drop_readonly(:user_options, :discourse_rewind_disabled)
+
+ change_column_default :user_options, :discourse_rewind_disabled, false
+
+ remove_column :user_options, :discourse_rewind_enabled
+ end
+end
diff --git a/plugins/discourse-rewind/db/post_migrate/20260105171226_drop_discourse_rewind_disabled_from_user_options.rb b/plugins/discourse-rewind/db/post_migrate/20260105171226_drop_discourse_rewind_disabled_from_user_options.rb
new file mode 100644
index 00000000000..df2a40a4ad6
--- /dev/null
+++ b/plugins/discourse-rewind/db/post_migrate/20260105171226_drop_discourse_rewind_disabled_from_user_options.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class DropDiscourseRewindDisabledFromUserOptions < ActiveRecord::Migration[7.2]
+ DROPPED_COLUMNS = { user_options: %i[discourse_rewind_disabled] }
+
+ def up
+ # Repeat the backfill in case any data was added during the deploy window
+ execute <<~SQL
+ UPDATE user_options
+ SET discourse_rewind_enabled = NOT discourse_rewind_disabled
+ WHERE discourse_rewind_enabled != (NOT discourse_rewind_disabled)
+ SQL
+
+ DROPPED_COLUMNS.each { |table, columns| Migration::ColumnDropper.execute_drop(table, columns) }
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/discourse-rewind/plugin.rb b/plugins/discourse-rewind/plugin.rb
index efe675882db..e393df9af8f 100644
--- a/plugins/discourse-rewind/plugin.rb
+++ b/plugins/discourse-rewind/plugin.rb
@@ -45,12 +45,8 @@ require_relative "lib/discourse_rewind/engine"
after_initialize do
UserUpdater::OPTION_ATTR.push(:discourse_rewind_enabled, :discourse_rewind_share_publicly)
- # TODO: Rename the `discourse_rewind_disabled` column to `discourse_rewind_enabled` and remove these
- add_to_class(:user_option, :discourse_rewind_enabled) { !discourse_rewind_disabled }
-
- add_to_class(:user_option, :discourse_rewind_enabled=) do |value|
- self.discourse_rewind_disabled = !ActiveModel::Type::Boolean.new.cast(value)
- end
+ # TODO: Remove once 20260105171115_rename_discourse_rewind_disabled_to_enabled has been promoted to pre-deploy
+ UserOption.ignored_columns += %i[discourse_rewind_disabled]
add_to_class(:user, :discourse_rewind_and_profile_public?) do
self.user_option.discourse_rewind_share_publicly && !self.user_option.hide_profile