Describe the bug
I am currently unable to successfully run prisma init on a clean/new mysql database running on my localhost. Initially I thought this might be a duplicate of #2516, but its seems possibly this is different?
To Reproduce
$ prisma init myproj
? Set up a new Prisma server or deploy to an existing server? Use existing database
? What kind of database do you want to deploy to? MySQL
? Does your database contain existing data? No
? Enter database host 127.0.0.1
? Enter database port 3306
? Enter database user root
? Enter database password
Connecting to database... !
Error: Could not connect to database. Connection terminated unexpectedly
at EndpointDialog.
at step (/usr/local/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/utils/EndpointDialog.js:40:23)
at Object.throw (/usr/local/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/utils/EndpointDialog.js:21:53)
at rejected (/usr/local/lib/node_modules/prisma/node_modules/prisma-cli-core/dist/utils/EndpointDialog.js:13:65)
at
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
Exiting with code: 1
Note that it doesn't prompt me for a schema in my mysql database before crashing. Also note that I have validated my MySql server is running locally and is accessable using the credentials shown. I also have looked through the output printed after setting export DEBUG="*" but I didn't immediately see anything.
Expected behavior
I suppose firstly, I'd expect it to not crash with an "unexpected error". Stated differently, if I am doing something wrong, I'd expect it to tell me what I am missing rather than display a development stack trace.
Versions (please complete the following information):
prisma CLI: [e.g. prisma/1.9.0 (darwin-x64) node-v10.4.0]Just a quick observation on my part after looking at the code in EndpointDialog.ts:
In the handleChoice method which is where the error mentioned in the description seems to be originating from. It seems possibly a Postgres database is always assumed based on the usage of the PostgresConnector? I haven't yet looked into the PostgresConnector method itself.
const connector = new PostgresConnector(client)
const introspector = new Introspector(connector)
let schemas
try {
schemas = await introspector.listSchemas()
} catch (e) {
throw new Error(`Could not connect to database. ${e.message}`)
}
? Set up a new Prisma server or deploy to an existing server? Use existing database
? What kind of database do you want to deploy to? MySQL
These options should not be accessible in the CLI yet - connecting to existing MySQL databases is not possible.
Let me clarify this statement, as it can be very confusing. There are two possible meanings of "connecting to an existing MySQL database":
1) Connect to an existing MySQL database that is already running, for example by your cloud provider, but you will deploy a completely new datamodel from scratch. This is currently possible already, by adjusting the docker-compose.yml file to connect to the database. Afterwards, run prisma deploy with a new datamodel, and it will deploy a new database to your MySQL host.
2) Introspect the datamodel for an existing database within your MySQL host. Meaning, you already have a database with tables, columns and data, and you simply want Prisma to connect to it, but you don't want to deploy a new database there. This is what the CLI refers to "existing database", and it is currently not possible for MySQL, only for Postgres. This option should be removed for MySQL from the CLI until it is implemented. Here is a feature request for MySQL introspection #2506.
I hope that clarifies the situation 🙂Let me know if you have ideas on how to make those differences clear in the terminology.
Ok, I misunderstood your situation! The options exposed in the CLI are actually correct.
My 2. point from above relates to answering "Yes" to the question of "Does your database contain existing data?". If you currently choose "No" for MySQL, you will correctly be told
â–¸ Existing MySQL databases with data are not yet supported.
I just managed to reproduce your bug either way.
One hypothesis for the cause is the automatic mapping we do for localhost in this line https://github.com/prisma/prisma/blob/c72588d91ad922c7e4bc5d1b743e039f591fbbb9/cli/packages/prisma-cli-core/src/utils/EndpointDialog.ts#L397-L400
Another hypothesis is that this problem is related to #3153.
We'll look closer into this.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Ok, I misunderstood your situation! The options exposed in the CLI are actually correct.
My 2. point from above relates to answering "Yes" to the question of "Does your database contain existing data?". If you currently choose "No" for MySQL, you will correctly be told
I just managed to reproduce your bug either way.
One hypothesis for the cause is the automatic mapping we do for
localhostin this line https://github.com/prisma/prisma/blob/c72588d91ad922c7e4bc5d1b743e039f591fbbb9/cli/packages/prisma-cli-core/src/utils/EndpointDialog.ts#L397-L400Another hypothesis is that this problem is related to #3153.
We'll look closer into this.