nas/db/migrate/20231023083359_convert_dtl_force_settings.rb
KMY(雪あすか) ae865975d4
Change: #70 DTL投稿で、公開範囲・検索許可を別々に設定 (#177)
* Bump version to 8.0

* Add: 他のサーバーに公開する情報に、制限設定などを追加

* Fix: `quote_of_id`のインデックス

* Fix: #172 他のサーバーからの相乗り絵文字削除が反映されない

* Test: #166 リモートから自分の絵文字を受け取った時、ライセンスが上書きされないことを確認するテスト

* Change: #70 DTL投稿で、公開範囲・検索許可を別々に設定
2023-10-26 22:06:51 +09:00

52 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
class ConvertDtlForceSettings < ActiveRecord::Migration[7.0]
include Mastodon::MigrationHelpers
disable_ddl_transaction!
class User < ApplicationRecord; end
def up
safety_assured do
User.transaction do
User.find_in_batches do |users|
users.filter { |user| user.settings.present? }.each do |user|
json = Oj.load(user.settings, symbol_keys: true)
dtl_force_with_tag = json.delete(:dtl_force_with_tag)
next if dtl_force_with_tag.blank?
json[:dtl_force_visibility] = dtl_force_with_tag == 'full' ? 'unlisted' : 'unchange'
json[:dtl_force_searchability] = dtl_force_with_tag == 'none' ? 'unchange' : 'public'
user.update(settings: Oj.dump(json))
end
end
end
end
end
def down
safety_assured do
User.transaction do
User.find_in_batches do |users|
users.filter { |user| user.settings.present? }.each do |user|
json = Oj.load(user.settings, symbol_keys: true)
dtl_force_visibility = json.delete(:dtl_force_visibility)
dtl_force_searchability = json.delete(:dtl_force_searchability)
next unless dtl_force_visibility.present? || dtl_force_searchability.present?
json[:dtl_force_with_tag] = case dtl_force_visibility
when 'unlisted'
'full'
else
dtl_force_searchability == 'unchange' ? 'none' : 'searchability'
end
user.update(settings: Oj.dump(json))
end
end
end
end
end
end