Skip to content

Better handling of phone numbers in import_membership script

Kyle Billemeyer requested to merge jeff-import_roster_fixes into dev

Summary of Changes

  1. Fix issue where phone numbers aren't imported for new members.

  2. Improve handling of international phone numbers.

  3. Improve batch writes to the database.

  4. New migration script that changes all VARCHAR and TEXT columns to utf8mb4 to better handle international character sets.

  5. Add local tmp/ folder to .gitignore. This folder will be added to the docker image through the docker/api/Dockerfile. It is just a simple way for me to add sensitive CSVs that can be used by the runjob script within the local api container without worrying about accidentally checking them in. It may be preferable to set up a volume as a future improvement.

  6. Name api and db containers through docker-compose config. This allows you to call 'docker exec -it [dsaapi/dsadb] [command] instead of having to look up the dynamically generated container id. Note, this will not work if we ever change our compose config to spin up multiple instances of either service.

  7. Make runjob callable through docker exec. For instance:

docker exec -it dsaapi ./runjob.py import_membership -f tmp/[import_script_filename].csv

Testing the import script

  1. Add your copy of the import csv to the tmp folder. PLEASE DOUBLE CHECK THIS IS ACTUALLY IGNORED GIT SO YOU DON'T ACCIDENTALLY UPLOAD SENSITIVE DATA.

  2. Run 'make stalin' to ensure that the api/db images will be recreated and include the Dockerfile/Compose edits, database migrations and drop any existing data in the db.

  3. Run 'make' to recreate images/db and run app.

  4. Run the import job using the command below, keeping in mind this will not work if you don't do step 2. You should see phone numbers being written now.

docker exec -it dsaapi ./runjob.py import_membership -f tmp/[import_script_filename].csv
  1. Re-run the above command to verify there are no issues attempting to import data that has already been loaded.

Exporting CSV data for Assembly canvassing (For Jeff)

The following command can be used to export phone number/member data from the database in a (csv) format that can be uploaded to excel/google sheets. Note, this command is designed to query the local, docker hosted db. The second command can be used to query against the prod database once these changes have been promoted.

docker exec -it dsadb mysql --user=root -p[Password] --column-names -B -e "SELECT * FROM dsa.members as m JOIN dsa.phone_numbers as p ON m.id = p.member_id;" | sed "s/'/\'/;s/\t/,/g;s/\n//g" > tmp/phone_numbers_pull.csv

Note: The -p[Password] intentionally has on space. It would look like -pMyPass.

mysql -u [username] -h api.dsasf.org -p[Password] --column-names -B -e "SELECT * FROM dsa.members as m JOIN dsa.phone_numbers as p ON m.id = p.member_id;" | sed "s/'/\'/;s/\t/,/g;s/\n//g" > [local file path]
Edited by Jeff May

Merge request reports