~cytrogen/masto-fe

ref: 9bb2fb6b1484c90c5b2c6cc52ce148019e82a3e2 masto-fe/db/migrate/20190314181829_migrate_open_registrations_setting.rb -rw-r--r-- 679 bytes
9bb2fb6b — Claire Change importers to avoid a few inefficiencies (#26721) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

class MigrateOpenRegistrationsSetting < ActiveRecord::Migration[5.2]
  def up
    open_registrations = Setting.find_by(var: 'open_registrations')
    return if open_registrations.nil? || open_registrations.value

    setting = Setting.where(var: 'registrations_mode').first_or_initialize(var: 'registrations_mode')
    setting.update(value: 'none')
  end

  def down
    registrations_mode = Setting.find_by(var: 'registrations_mode')
    return if registrations_mode.nil?

    setting = Setting.where(var: 'open_registrations').first_or_initialize(var: 'open_registrations')
    setting.update(value: registrations_mode.value == 'open')
  end
end