1

I have a Ruby on Rails application with around 300 email subscribed. For technical reasons I had to modify a good part of the database, if I save the old user email and the password_digest, can I insert in my new database the old user manteining their old password?

To store password I use the following gem:

gem 'bcrypt'

In every model I have this:

 has_secure_password

In the migration:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
      t.string :email
      t.string :password_digest
      ...
    end
  end
end

This allows me to save the password by simply doing

 user = User.find x
 user.password = "password"
 user.save

The perfect solution for me would be saving my current email and password_digest so the user in the new database will have the same password. Is that possible?

ste
  • 3,087
  • 5
  • 38
  • 73

1 Answers1

0

So you have several options available to you. If you are going to be keeping the User table structure the same then you can export a sql dump of the user table and just import it back into the new database and it should work like nothing ever happened.

see this answer How to take backup of a single table in a MySQL database?

You could also export the contents to a CSV then write a script to import the user information back into the database.

I would go with the database dump solution though, also most importantly BACKUP YOUR ENTIRE DATABASE BEFORE HAND.

Community
  • 1
  • 1
C dot StrifeVII
  • 1,885
  • 1
  • 16
  • 21
  • Yes actually I did what you suggested, I only needed to delete the table structure from the .sql dump file! – ste Oct 19 '16 at 14:25