icefoganalytics / travel-authorization

0 stars 0 forks source link

Make Seeding Non-Destructive #212

Closed klondikemarlen closed 4 months ago

klondikemarlen commented 4 months ago

Fixes https://github.com/icefoganalytics/travel-authorization/issues/72

Relates to

Context

In the current environment the seeding system is idempotent, which is good, but it's also destructive, which is not. Normally seeds would use a "find or create by" pattern rather than a "destroy all, then recreate".

This ticket is to rebuild the seeding system using the "find or create by" style.

Why? The current destructive nature of the seeds, makes it hard to debug issues in the QA environment, as any new deploy wipes old data.

Implementation

Move .csv copy build code from package script to Dockerfile. Standardize roles table. Delete some unused db data files. Move seed data .csv files to /db/seeds/data/*.csv to make them easier to find. Make all seeds idempotent. Remove seeds that created super admin users by emails, as these users don't actually support login since there auth0 subjects don't match. This caused duplicate users to exist. Move distance matrix seeds to a .csv file. Load all data from database in seeds instead of using hard-code ids to make the code less fragile. Make all user searches by email lower case the email. Fix logging in dev helper when using "knex", "seed", "migrate" command.

Testing Instructions

  1. Build a production build via docker compose build
  2. Boot the production build via docker compose up
  3. Check that the seeds run without issue.
  4. Stop the production build via docker compose down
  5. Run the test suite via dev test (or dev test_api)
  6. Set SKIP_SEEDING_UNLESS_EMPTY=false in your .env.development or remove it entirely
  7. Boot the app via dev up
  8. Check that the seeds run without issue.
  9. Drop the database via dev down -v
  10. Boot the app again via dev up
  11. Check that the seeds run without issue.
  12. Log in to the app at http://localhost:8080
  13. Go to http://localhost:8080/administration/users
  14. Click on your user to edit them.
  15. Add all roles to your user and check that the roles are now descriptive.
  16. Click save user.
  17. Go to your profile page at http://localhost:8080/profile.
  18. Check that the roles are now descriptive and prettily formatted.