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
Build a production build via docker compose build
Boot the production build via docker compose up
Check that the seeds run without issue.
Stop the production build via docker compose down
Run the test suite via dev test (or dev test_api)
Set SKIP_SEEDING_UNLESS_EMPTY=false in your .env.development or remove it entirely
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
docker compose build
docker compose up
docker compose down
dev test
(ordev test_api
)SKIP_SEEDING_UNLESS_EMPTY=false
in your .env.development or remove it entirelydev up
dev down -v
dev up