Skip to content
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

[Introspection] Better handling of "Error: Empty introspection result for ..." #1145

Closed
janpio opened this issue Dec 15, 2019 · 7 comments
Closed
Assignees
Labels
kind/improvement An improvement to existing feature and code. topic: introspection topic: prisma db pull CLI: prisma db pull
Milestone

Comments

@janpio
Copy link
Member

janpio commented Dec 15, 2019

When you introspect an empty database, currently you get an error:

Error: Empty introspection result for mysql://prisma:...@mysql127-divy.cg7tbvsdqlrs.eu-central-1.rds.amazonaws.com:3306/ctu_vondreli

We have to figure out what we can and want to do here:

  1. Hard crash as right now (bad, because user has to redo whole input)
  2. Show this error and make them go back and change the database credentials (good, but maybe for some reason they want the empty DB?)
  3. Ask them if they are sure they want to use an empty DB, just write the connection string to the model (good, but why would someone want to do that?)
  4. Just accept that the user wants an empty database and write it to the model (bad, as they maybe were not aware that the DB was empty and will wonder about that when looking at the schema)

Update: See below.

@janpio
Copy link
Member Author

janpio commented Jan 31, 2020

Now that fancy init is gone, the connection string had to be set manually in schema.prisma for this to occur - so the only real option is to tell the user what is happening in a nice way.

@janpio
Copy link
Member Author

janpio commented Feb 4, 2020

Next steps: @do4gr will find out where the error comes from in Introspection. Then we will decide on the text and how to display the error (probably without the error reporting prompt, but as a nice message to the user before exiting the command)

@melounek
Copy link

melounek commented Feb 4, 2020

🙏see the same with postgres

$ prisma2 introspect
Introspecting based on datasource defined in schema.prisma …
Error: Empty introspection result for postgres://qsucrxrlmhhtqu:secret@ec2-176-34-237-141.eu-west-1.compute.amazonaws.com:5432/d440sh15d6mf8s

@janpio
Copy link
Member Author

janpio commented Feb 5, 2020

Had a conversation with @timsuchanek about this:

Seems the error message is actually from CLI, not the Engine - so we can easily change it 👍


This means we have to decide what to do here:

Options:
a) Tell the user to try again with non empty database
b) Tell them additionally how to work from the empty datamodel (create tables manually, re-introspect OR define datamodel and migrate)

Text suggestion for a):

The introspected database was empty: mysql://prisma:...@introspection-public-mysql-cluster.cluster-ro-clfeqqifnebj.eu-west-1.rds.amazonaws.com:3306/empty

prisma introspect can not create any models in your schema.prisma file based on that and you will not be able to prisma2 generate a Prisma Client.

You should edit your schema.prisma and replace the datasource.url with a database that contains tables, then run prisma2 introspect again.

Alternative additional text for b):

You can also create your tables in this database now manually, and then run prisma2 introspect again to update your datamodel in schema.prisma.
Alternatively you can write your datamodel by hand and then migrate your database manually: https://pris.ly/d/whatever

(https://pris.ly/d/whatever then shows instructions on how to migrate manually)

What do you think @nikolasburk?


Connection string to reproduce: https://github.com/prisma/introspection-engine-output/blob/fdefff6a0ffb592c70e7060e28a410196089a5ab/connections/mysql_public.txt#L9

@janpio janpio unassigned do4gr Feb 5, 2020
@nikolasburk
Copy link
Member

nikolasburk commented Feb 5, 2020

Thanks Jan, I think showing both option make sense 👍 I adjusted the formatting a bit to show the options in a list and adjusted some wording:

The introspected database was empty: mysql://prisma:...@introspection-public-mysql-cluster.cluster-ro-clfeqqifnebj.eu-west-1.rds.amazonaws.com:3306/empty

`prisma2 introspect` could not create any models in your `schema.prisma` file and you will not be able to generate Prisma Client with the `prisma2 generate` command.

To fix this, you have two options:

- manually create a table in your database (using SQL).
- make sure the database connection URL inside the `datasource` block in `schema.prisma` points to a database that is not empty (it must contain at least one table).

Then you can run `prisma2 introspect` again. 

@Jolg42
Copy link
Member

Jolg42 commented Feb 7, 2020

Implemented like this
Screen Shot 2020-02-07 at 15 58 34

@janpio
Copy link
Member Author

janpio commented Feb 7, 2020

There was an update on the text in Slack channel by @schickling that doesn't seem to have made it to here @nikolasburk - I do not remember where though. Just remember seeing it somewhere.

@janpio janpio added topic: prisma db pull CLI: prisma db pull and removed topic: prisma introspect labels Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. topic: introspection topic: prisma db pull CLI: prisma db pull
Projects
None yet
Development

No branches or pull requests

7 participants