Open psirenny opened 1 year ago
One of our "opinions" is:
Roles should be managed outside of migrations (since they can be shared between databases)
Managing them in lifecycle scripts is not unreasonable. I personally handle role creation in a separate process, but I can understand the desire to centralize.
beforeReset
was intended to be a chance to dump your old DB (or similar) if you wanted to, before it's deleted and a new one created.
I think maybe we want a new hook beforeDatabaseCreate
that runs after beforeReset
, after the database is dropped, but before the database is recreated and before afterReset
.
This would be a special hook since we know that the database doesn't exist; so it wouldn't make sense to pass it the connection string to the database. Instead it should use the rootConnectionString
. I'm thinking a !!
prefix to indicate this, such as beforeDatabaseCreate:["!!createRoles.sql"]
.
Would you like to experiment with this approach?
@benjie what's your separate process to handle role creation? Is it manual?
Feature description
It would be a great developer experience if the Owner and Authenticator roles could be created on
reset
if they don't already exist. The tool could create the roles automatically or allow developers to do so themselves in hooks.If the tool handled it automatically, then it could take additional placeholder variables:
Motivating example
I'm initializing a database for the first time and trying to avoid writing a one-off
setup_db.js
script by hooking into the graphile-migrate event system.I tried to create the default roles in an
!afterReset.sql
script like so:However, this fails because graphile-migrate attempts to run the script as the Owner before the Owner is created:
I was surprised by the error because I expected graphile-migrate to connect as the root user.
Alternatively, I tried creating the default roles in a
!beforeReset.sql
script. However, this fails because thebeforeReset
hook expects the database to exist before it's been created:Creating these roles is something all graphile-migrate users have to do, so all of us could benefit from this feature 😄.
Breaking changes
I don't think so.
Supporting development
I [tick all that apply]: