diff options
Diffstat (limited to 'db/post_migrate/20210407150240_confirm_support_bot_user.rb')
-rw-r--r-- | db/post_migrate/20210407150240_confirm_support_bot_user.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/db/post_migrate/20210407150240_confirm_support_bot_user.rb b/db/post_migrate/20210407150240_confirm_support_bot_user.rb new file mode 100644 index 00000000000..c26ae153128 --- /dev/null +++ b/db/post_migrate/20210407150240_confirm_support_bot_user.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +class ConfirmSupportBotUser < ActiveRecord::Migration[6.0] + SUPPORT_BOT_TYPE = 1 + + def up + users = Arel::Table.new(:users) + um = Arel::UpdateManager.new + um.table(users) + .where(users[:user_type].eq(SUPPORT_BOT_TYPE)) + .where(users[:confirmed_at].eq(nil)) + .set([[users[:confirmed_at], Arel::Nodes::NamedFunction.new('COALESCE', [users[:created_at], Arel::Nodes::SqlLiteral.new('NOW()')])]]) + connection.execute(um.to_sql) + end + + def down + # no op + + # The up migration allows for the possibility that the support user might + # have already been manually confirmed. It's not reversible as this data is + # subsequently lost. + end +end |