SeedCompany / cord-api-v3

Bible translation project management API
MIT License
18 stars 4 forks source link

Refactor root user creation #3163

Closed CarsonF closed 6 months ago

CarsonF commented 6 months ago

Now the root user is created on boot with EdgeDB, matching Neo4j functionality. It is also created in the seed files, which allows the DB to wiped and successfully re-seeded.

This also allows both DBs to configure the email address for the root user.

ROOT_USER='{"email": "foo@bar.com", "password": "changeme"}'
# Each part can be given in it's on key too which will override the json object above
ROOT_USER_EMAIL=foo@bar.com
ROOT_USER_PASSWORD=changeme

The root user ID can also be configured in env, but specifying this is questionable, and probably not necessary to worry about. Neo4j will always update the root user to match. EdgeDB will only use that ID when the root user is insert. I've specified a static ID to use for local development that way the ID is stable across rebuilds / among us.

For EdgeDB, I've removed the alias RootUser which keyed off of the static email address. Now instead we use a "root" Alias to achieve the root user lookup while allowing a dynamic ID/email.

Removing the root user insert from the migrations/ folder was important. EdgeDB is not expecting these migrations to seed data, but rather only adjust preexisting data if needed with a schema migration change. Wiping the DB would not re-insert the root user from this migration script. Again, that's why it's now in the seeds & on app boot.