-
Notifications
You must be signed in to change notification settings - Fork 108
Generating a csv of the current users table
Occasionally our execs might ask for a csv of the users table (or a list of our current members). Here is how you generate that:
See this documentation on how to access the production Rails console
Once you are in the rails console, run this code (changing the columns if you desire to:
require 'csv'
file = "#{Rails.root}/user_data.csv"
users = User.all
column_headers = ["User ID", "First Name", "Last Name", "Email", "Zip"]
CSV.open(file, 'w', write_headers: true, headers: column_headers) do |writer|
users.each do |user|
writer << [user.id, user.first_name, user.last_name, user.email, user.zip]
end
end
Go ahead and exit out of the console, now run this command (still in the container)
(in container) $ ls
You should see a file called "user_data.csv".
Now exit out of the container you are ssh'd into
(in container) $ exit
And run this command from your local workstation to copy the file from the container to your local workstation
(local workstation) $ kubectl cp operationcode/operationcode-backend-identifer:/app/user_data.csv ./user_data.csv
The identifier
needs to be replaced with an actual pod's name. You get that from:
(local workstation) $ kubectl get pods -n operationcode
A sample command to copy the file, with the identifier, looks like this:
(local workstation) $ kubectl cp operationcode/operationcode-backend-64db899b64-7qxfv:/app/user_data.csv ./user_data.csv
You may see a warning along the lines of "tar: Removing leading `/' from member names" - don't worry about it, the file copy will still work.
Now run "ls" in the directory you are currently in on your workstation
(local workstation)$ ls
And you should see user_data.csv!