Sha256: c6765b81fe194c5db1600b339c5f95253df379773569a66822b17bcadf489162

Contents?: true

Size: 545 Bytes

Versions: 7

Compression:

Stored size: 545 Bytes

Contents

class AddFirstAdminUser < ActiveRecord::Migration[6.0]
  def up
    email = "admin@example.com"
    User.reset_column_information
    u=User.find_or_initialize_by(email: email)
    psswd = SecureRandom.hex(5)
    u.password = psswd
    u.password_confirmation = psswd
    u.admin = true
    u.save!
    puts "\nPlease find generated initial admin password in .passwords file."
    File.open('.passwords', 'w') do |f|
      f.write(psswd)
    end
  end

  def down
    email = "admin@example.com"
    User.find_by(email: email).destroy
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
thecore_auth_commons-2.2.2 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.2.1 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.2.0 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.1.9 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.1.8 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.1.7 db/migrate/20200306151541_add_first_admin_user.rb
thecore_auth_commons-2.1.5 db/migrate/20200306151541_add_first_admin_user.rb