Use SecureRandom.uuid over SecureRandom.urlsafe_base64

parent 8b4c08a0
......@@ -8,18 +8,11 @@ class AddUuidToApplicationSettings < ActiveRecord::Migration
def up
add_column :application_settings, :uuid, :string
add_concurrent_index :application_settings, :uuid
execute("UPDATE application_settings SET uuid = #{quote(generate_random_string(40))}")
execute("UPDATE application_settings SET uuid = #{quote(SecureRandom.uuid)}")
end
def down
remove_index :application_settings, :uuid if index_exists?(:application_settings, :uuid)
remove_column :application_settings, :uuid
end
private
def generate_random_string(size)
# urlsafe_base64 may return a string of size * 4/3
SecureRandom.urlsafe_base64(size)[0, size]
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment