2
0

Add migration to fill unset default quote policy based on default post privacy (#36041)

This commit is contained in:
Claire
2025-09-11 12:11:31 +02:00
committed by GitHub
parent 75f78244d5
commit f7289b251f
2 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
# frozen_string_literal: true
class FillDefaultQuotePolicySetting < ActiveRecord::Migration[8.0]
disable_ddl_transaction!
# Dummy classes, to make migration possible across version changes
class User < ApplicationRecord; end
def up
User.where.not(settings: nil).find_each do |user|
settings = Oj.load(user.attributes_before_type_cast['settings'])
next if settings.nil?
should_update_settings = false
if settings['notification_emails.quote'].blank? && settings['notification_emails.reblog'] == false && settings['notification_emails.mention'] == false
settings['notification_emails.quote'] = false
should_update_settings = true
end
if settings['default_privacy'] == 'private' && settings['default_quote_policy'] != 'nobody'
settings['default_quote_policy'] = 'nobody'
should_update_settings = true
elsif settings['default_quote_policy'].nil? && settings['default_privacy'] == 'unlisted'
settings['default_quote_policy'] = 'followers'
should_update_settings = true
end
user.update_column('settings', Oj.dump(settings)) if should_update_settings
end
end
end

View File

@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_09_09_100506) do ActiveRecord::Schema[8.0].define(version: 2025_09_11_163952) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"