You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accept the defaults for project name, email, postgres username and postgres password
Results
Fails with error: role "postgres" does not exist:
npx create-medusa-app@latest --with-nextjs-starter
? What's the name of your project? my-medusa-store
? Enter an email for your admin dashboard user [email protected]
? Enter your Postgres username postgres
? Enter your Postgres password [hidden]
Couldn't connect to PostgreSQL because of the following error: error: role "postgres" does not exist.
Make sure you have PostgreSQL installed and the credentials you provided are correct.
You can learn how to install PostgreSQL here: https://docs.medusajs.com/development/backend/prepare-environment?os=macos#postgresql
If you keep running into this issue despite having PostgreSQL installed, please check out our troubleshooting guidelines: https://docs.medusajs.com/troubleshooting/database-error
Expected results
npx create-medusa-app@latest --with-nextjs-starter should succeed
SOLUTION
Create a postgres role with all privileges:
Important
psql -U $USER -d postgres -c 'CREATE ROLE "postgres"' \
-c 'ALTER ROLE "postgres" WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS'
To verify the role was created, you should now see ${USER} and postgres when dumping the roles:
psql -U $USER -d postgres -c '\du'
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
${USER}| Superuser, Create role, Create DB, Replication, Bypass RLS | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
Substitute ${USER} below with your currently logged in OSX username
brew install postgres on OSX installs postgres@14 and does the following:
creates a role ${USER} with no password
grants the ${USER} role all privileges
creates a database postgres
npx create-medusa-app@latest --with-nextjs-starter appears to assume the database name and the role name are the same, which results in either a database or role error when they don't match.
when specifying ${USER} for the Postgres username:
Couldn't connect to PostgreSQL because of the following error: error: database "${USER}" does not exist.
when specifying postgres (or default) for the Postgres username:
Couldn't connect to PostgreSQL because of the following error: error: role "postgres" does not exist.
Upon inspecting the create-medusa-app npm module source in the medusa v1.20.4 tag, we see that the user is prompted to enter their database username and password, but not the database name.
In utils/create-db.ts, prompt the user to specify their database name (with a default of postgres):
{type: "input",name: "postgresDatabaseName",message: "Enter your Postgres database name",default: "postgres",validate: (input)=>{returntypeofinput==="string"&&input.length>0},},])postgresUsername=answers.postgresUsernamepostgresPassword=answers.postgresPasswordpostgresDatabaseName=answers.postgresDatabaseName
When the initial db connection with username postgres and database name postgres fails, automatically attempt to connect using username: process.env.USER and database name: postgres
Issue
Note
This is a reproduction of bug #4999
Running
npx create-medusa-app@latest --with-nextjs-starter
fails witherror: role "postgres" does not exist
Environment
Versions:
Steps to reproduce
brew install postgres
npx create-medusa-app@latest --with-nextjs-starter
Results
Expected results
npx create-medusa-app@latest --with-nextjs-starter
should succeedSOLUTION
postgres
role with all privileges:Important
${USER}
and postgres when dumping the roles:create-medusa-app
againFurther Analysis
Note
Substitute
${USER}
below with your currently logged in OSX usernamebrew install postgres
on OSX installspostgres@14
and does the following:${USER}
with no password${USER}
role all privilegespostgres
npx create-medusa-app@latest --with-nextjs-starter
appears to assume the database name and the role name are the same, which results in either a database or role error when they don't match.${USER}
for thePostgres username
:postgres
(or default) for thePostgres username
:create-medusa-app
npm module source in the medusav1.20.4
tag, we see that the user is prompted to enter their database username and password, but not the database name.medusa/packages/create-medusa-app/src/utils/create-db.ts
Lines 63 to 85 in 2524a9d
Potential fixes
utils/create-db.ts
, prompt the user to specify their database name (with a default ofpostgres
):postgres
and database namepostgres
fails, automatically attempt to connect using username:process.env.USER
and database name:postgres
Originally posted by @kensteele in #4743 (comment)
The text was updated successfully, but these errors were encountered: