discourse/db/migrate/20190312181641_migrate_email_user_options.rb
Penar Musaraj 9334d2f4f7
FEATURE: add more granular user option levels for email notifications (#7143)
Migrates email user options to a new data structure, where `email_always`, `email_direct` and `email_private_messages` are replace by

* `email_messages_level`, with options: `always`, `only_when_away` and `never` (defaults to `always`)
* `email_level`, with options: `always`, `only_when_away` and `never` (defaults to `only_when_away`)
2019-03-15 10:55:11 -04:00

30 lines
772 B
Ruby

class MigrateEmailUserOptions < ActiveRecord::Migration[5.2]
def up
# see UserOption.email_level_types
# always = 0, only_while_away: 1, never: 2
add_column :user_options, :email_level, :integer, default: 1, null: false
add_column :user_options, :email_messages_level, :integer, default: 0, null: false
execute <<~SQL
UPDATE user_options
SET email_level = CASE
WHEN email_direct AND email_always
THEN 0
WHEN email_direct AND email_always IS NOT TRUE
THEN 1
ELSE 2
END,
email_messages_level = CASE
WHEN email_private_messages
THEN 0
ELSE 2
END
SQL
end
def down
# See postmigration: 20190312194528_drop_email_user_options_columns.rb
end
end