I’m starting with Elixir, Phoenix, and back-end development, coming from a front-end background using React. However, I’m currently facing an issue for which I can’t find a clear solution. Perhaps you could help me.
I developed an app locally that manages two roles: admin and user. It works fine because I manually assigned the admin role to the first user. Now, I’ve deployed the app on Fly.io following the Phoenix documentation, but by default, users only have the “user” role.
My question is: what is the best way to add the first admin user to the production database? The first option that came to mind was to connect to the database through the terminal and do it manually, but I wonder if there is a better practice that is less error-prone.
I don’t think there is a “this is the best alternative” option since every app has its own rules.
In your case, other than inserting/updating directly in the database, I guess you could have a migration to bootstrap an “admin” user, but any secrets would be saved in the git history (e.g., password, hash, etc). This might not be desirable.
Since you have access to the nodes as an owner of the fly.io account, another alternative could be to connect remotely to a node, and execute a function that creates the admin user. This way you could use the Ecto schema, changesets, etc, thus giving you more control and maybe a less error prone path.