1# frozen_string_literal: true
2
3class MigrateTimelinePreviewSetting < ActiveRecord::Migration[8.0]
4 class Setting < ApplicationRecord; end
5
6 def up
7 Setting.reset_column_information
8
9 setting = Setting.find_by(var: 'timeline_preview')
10 return unless setting.present? && setting.attributes['value'].present?
11
12 value = YAML.safe_load(setting.attributes['value'], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol])
13
14 Setting.upsert_all(
15 %w(local_live_feed_access remote_live_feed_access local_topic_feed_access remote_topic_feed_access).map do |var|
16 { var: var, value: value ? "--- public\n" : "--- authenticated\n" }
17 end,
18 unique_by: index_exists?(:settings, [:thing_type, :thing_id, :var]) ? [:thing_type, :thing_id, :var] : :var
19 )
20 end
21
22 def down; end
23end
24