Skip to content

Commit

Permalink
Safe migration
Browse files Browse the repository at this point in the history
  • Loading branch information
elektronaut committed Feb 2, 2024
1 parent 2c94c64 commit e42af67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ Rails/HelperInstanceVariable:
Rails/OutputSafety:
Exclude:
- "app/formatters/pages_core/html_formatter.rb"

Rails/SkipsModelValidations:
Exclude:
- "db/migrate/**/*"
6 changes: 5 additions & 1 deletion db/migrate/20240126160700_add_2fa_fields.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class Add2faFields < ActiveRecord::Migration[7.0]
class User < ApplicationRecord; end

def change
change_table :users do |t|
t.boolean :otp_enabled, null: false, default: false
Expand All @@ -14,7 +16,9 @@ def change

reversible do |dir|
dir.up do
User.find_each { |u| u.update(session_token: SecureRandom.hex(32)) }
User.find_each do |u|
u.update_columns(session_token: SecureRandom.hex(32))
end
change_column_null :users, :session_token, false
end
end
Expand Down

0 comments on commit e42af67

Please sign in to comment.