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

Add prisma studio via db studio command #799

Merged
merged 3 commits into from
Jul 6, 2020
Merged

Add prisma studio via db studio command #799

merged 3 commits into from
Jul 6, 2020

Conversation

jtoar
Copy link
Contributor

@jtoar jtoar commented Jul 5, 2020

This PR adds a new db command: ide. It starts Prisma Studio.

yarn rw db ide

Note that you have to have a dev.db and a migrations directory in api/prisma for this to work. If either are missing, the command outputs:

[warning] your app doesn't have a database (api/prisma/dev.db) and/or migrations (api/prisma/migrations). Save and up before starting the IDE.

Design Question:

Should this actually just be a flag on dev like @thedavidprice suggested in #467?

yarn rw dev --prismastudio

I'm open to anything, I just finally got it to work this way and wanted to reopen the discussion with a working spike.

NOTE: I accidentally kind of overwrote #467, otherwise I would've just reopened that one.

Priority

Before attempting to write any kind of Prisma primer, I think we should get this one figured out. As Siddhant Sinha demoed on Prisma Day, you can use Prisma Studio as a playground for your Prisma Client—basically the equivalent of GraphiQL for GraphQL, which is super awesome.

@peterp
Copy link
Contributor

peterp commented Jul 5, 2020

This looks great!

I think having the command live in db makes the most sense to me, something like yarn rw db studio?

@jtoar
Copy link
Contributor Author

jtoar commented Jul 5, 2020

@peterp Renamed to yarn rw db studio. Using it locally and it's great. Is this one ok to merge or should we wait for more feedback / I should try to test something somehow?

@jtoar jtoar changed the title Add prisma studio via db ide command Add prisma studio via db studio command Jul 5, 2020
@nexneo
Copy link
Contributor

nexneo commented Jul 5, 2020

Note that you have to have a dev.db and a migrations directory in api/prisma for this to work

Why this limitation, if prisma studio needs this files then prisma studio should complain about it. Redwood can show this warning but should allow to run prisma studio if there is no such limitation in studio itself.

@jtoar
Copy link
Contributor Author

jtoar commented Jul 5, 2020

@nexneo There is a limitation. But the error message isn't very informative/could be better.

Say you don't have the dev.db file. Studio will start up, but won't actually work. Here's what the screen looks like:

rw-prisma-studio-fail

And the error message in the terminal:

Error in request:  {
  telemetry: true,
  message: 'Error occurred during query execution:\n' +
    'ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("no such table: dev.Post"))) })',
  stack: 'Error: Error occurred during query execution:\n' +
    'ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(SqliteFailure(Error { code: Unknown, extended_code: 1 }, Some("no such table: dev.Post"))) })\n' +
    '    at PrismaClientFetcher.request (/home/dominic/.cache/prisma/studio/home-dominic-projects-redwood-issues-and-prs-starter/runtime/index.js:1:149258)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:97:5)\n' +
    '    at async Promise.all (index 0)\n' +
    '    at async eval (eval at Photon.request (/home/dominic/projects/redwood/issues-and-prs/starter/node_modules/@prisma/cli/build/index.js:2:778638), <anonymous>:5:32)\n' +
    '    at async Photon.request (/home/dominic/projects/redwood/issues-and-prs/starter/node_modules/@prisma/cli/build/index.js:2:778632)\n' +
    '    at async PhotonService.respond (/home/dominic/projects/redwood/issues-and-prs/starter/node_modules/@prisma/cli/build/index.js:2:2402575)\n' +
    '    at async WebSocket.StudioServer.onWSMessage (/home/dominic/projects/redwood/issues-and-prs/starter/node_modules/@prisma/cli/build/index.js:2:1733647)',
  isPanic: undefined,
  code: undefined
} {
  query: 'Promise.all([\n    prisma.post.count(),\n    prisma.user.count(),\n])'
}

If you don't have schema.prisma, then it flat out won't start at all:

Error: Could not find schema.prisma
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Dominic and others added 3 commits July 5, 2020 15:02
@peterp
Copy link
Contributor

peterp commented Jul 6, 2020

@jtoar I think this is OK to merge

@jtoar jtoar merged commit d8919b8 into redwoodjs:main Jul 6, 2020
@nexneo
Copy link
Contributor

nexneo commented Jul 6, 2020

@jtoar We use postgresql so we don't have dev.db and also we don't use migrations as we use Rails migrations for now until we can move completely to redwood/prisma. I don't think it's very important as we can invoke studio directly but just pointing out. Thanks for the response!

@jtoar
Copy link
Contributor Author

jtoar commented Jul 6, 2020

@nexneo Ah got it—that makes sense. Maybe there should be a --skip-checks flag or something similar? Or do you think it's better to just let Prisma output its error message and hopefully people will figure it out?

Studio is still experimental so I'm sure things will get better in the near future too. I imagine some of the details of this command will change a lot.

@peterp
Copy link
Contributor

peterp commented Jul 6, 2020

Hmmm... @nexneo raises a valid point, we should just check if ./api/prisma/schema.prisma exists.

@jtoar
Copy link
Contributor Author

jtoar commented Jul 6, 2020

@peterp @nexneo Fix in #801!

@nexneo
Copy link
Contributor

nexneo commented Jul 6, 2020

@jtoar Awesome!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants