mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 09:23:39 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
37 lines
1.6 KiB
Ruby
37 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class MigrateDefaultUserEmailOptions < ActiveRecord::Migration[5.2]
|
|
def up
|
|
# see UserOption.email_level_types
|
|
# always = 0, only_while_away: 1, never: 2
|
|
|
|
email_always = DB.query_single("SELECT value FROM site_settings WHERE name = 'default_email_always'").first
|
|
email_direct = DB.query_single("SELECT value FROM site_settings WHERE name = 'default_email_direct'").first
|
|
email_personal_messages = DB.query_single("SELECT value FROM site_settings WHERE name = 'default_email_personal_messages'").first
|
|
|
|
default_email_level = nil
|
|
default_email_level = 0 if email_direct != 'f' && email_always == 't'
|
|
default_email_level = 2 if email_direct == 'f'
|
|
|
|
unless default_email_level.nil?
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
|
|
VALUES ('default_email_level', 7, #{default_email_level}, now(), now())"
|
|
end
|
|
|
|
default_email_messages_level = nil
|
|
default_email_messages_level = 0 if email_personal_messages != 'f' && email_always == 't'
|
|
default_email_messages_level = 2 if email_personal_messages == 'f'
|
|
|
|
unless default_email_messages_level.nil?
|
|
execute "INSERT INTO site_settings (name, data_type, value, created_at, updated_at)
|
|
VALUES ('default_email_messages_level', 7, #{default_email_messages_level}, now(), now())"
|
|
end
|
|
|
|
execute "DELETE from site_settings where name in ('default_email_always', 'default_email_direct', 'default_email_personal_messages')"
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|