-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: add db:create command #8760
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean PR, LGTM
FIXES: FRMW-2664
This PR introduces a new command called
db:create
. The command is meant to create the database (if it is missing) and update the.env
file after the operation has been successful.Important
This command does not boot the application nor read the
medusa-config.js
file. Thedb:create
command should work regardless of the state of the application. Otherwise, we might run into issues where a loader wants to establish the DB connection, but the database does not exist.How it works?
This is how the command works under the hood.
.env
file using theEnvEditor
and looks forDATABASE_URL
andDB_NAME
environment variables.DATABASE_URL
is missing. We need theDATABASE_URL
to make the database connection.DB_NAME
environment variable and falls back to the project directory name..env
file.Newly introduced utilities
The following utilities have been introduced to the
@medusajs/utils
package.EnvEditor
It reads the
.env
file as a text file and exposes the API to edit the values inside it and persist them on the disk.parseConnectionString
We need to parse the PG connection string and convert it into an object to safely remove the database name from the
DATABASE_URL
value. We need to remove the database name because we want to establish the connection without selecting this database since it might not exist in the first place.createClient
Creates the PostgreSQL client instance (Not the Mikro ORM)
createDb
Creates the database
dbExists
Check if the database exists.