1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-24 17:04:43 +00:00
Files
wrestlingdev.com/db/migrate/2025040700001_add_password_digest_to_users.rb

21 lines
928 B
Ruby

class AddPasswordDigestToUsers < ActiveRecord::Migration[6.1]
def change
# Add password_digest column if it doesn't already exist
add_column :users, :password_digest, :string unless column_exists?(:users, :password_digest)
# If we're migrating from Devise, we need to convert encrypted_password to password_digest
# This is a data migration that will preserve the passwords
reversible do |dir|
dir.up do
# Only perform if both columns exist
if column_exists?(:users, :encrypted_password) && column_exists?(:users, :password_digest)
execute <<-SQL
-- Copy over the encrypted_password to password_digest column for all users
-- Devise uses the same bcrypt format that has_secure_password expects
UPDATE users SET password_digest = encrypted_password WHERE password_digest IS NULL;
SQL
end
end
end
end
end