Nevertheless, despite setting up the `docker-compo...
# orm-help
b
Nevertheless, despite setting up the
docker-compose.yml
file correctly...
Copy code
prisma introspect
 β–Έ    Couldn’t find `prisma.yml` file. Are you in the right directory?
https://github.com/prisma/prisma/blob/665eb16138dfea9082746e21743121eccfc41419/cli/packages/prisma-yml/src/PrismaDefinition.ts#L79
c
Can you share you
docker-compose.yml
?
b
Yes, thanks for your attention.
c
What's the name of the folder where you have
prisma.yml
?
b
The tutorial makes no mention of needing a
prisma.yml
file, my dear fellow πŸ™‚
c
πŸ™‚
n
looks like step 6 and 7 have to be switched
can you try that, @br?
also, the link should be https://docs-beta.prisma.io/docs/1.15/get-started/01-setting-up-prisma-existing-database-a003/, yours doesn't work. Where did you get your link from?
b
@nilan Old link from yesterday still cached in my browser. Y'all have been fixing up some of the documentation links I think πŸ™‚
πŸ‘ 1
c
Totally agree. But still, there's a prisma.yml in the documentation πŸ™‚
πŸ’― 1
b
And yes, I shall try it, post-haste! (sorry I'm in an eccentric mood right now...)
πŸ˜„ 2
@catalinmiron That's true, but if you are trying to rapidly experiment with a whole bunch of shortcuts to connect your postgres db with the least amount of effort, and you're sleep deprived, such reasonable guesses as "maybe they have the steps mixed up" don't always jump to the front of ze 🧠 queue
n
I am not quite sure if the steps mixed up, but let's see! If this won't help, we have to look closer πŸ™‚
b
Let's have a lookee-see here.... hmmm... "the file that contains the data model"... Can that be a path to where to write that file to, rather than an existing file?
n
yup
b
Aha, jolly good show.
p.s. are the docs open-source? Because I would happily add some extra context like that detail which experienced people automatically infer but noobs easily miss.
c
b
Copy code
brpro ➜  database git:(develop) βœ— prisma introspect
  config CWD /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/database +0ms
  config HOME /Users/br +2ms
  config definitionDir /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/database +1ms
  config definitionPath /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/database/prisma.yml +0ms
  cli { isGlobal: true } +0ms
  StatusChecker setting status checker +0ms
  cli command id introspect +6ms
  cli:plugincache Got plugin from cache +0ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  cli:plugincache Got plugin from cache +2ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  plugins findCommand prisma-cli-core +0ms
  plugin requiring command +0ms
  cli-engine:plugins:manager requiring /Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core +0ms
  cli-engine:plugins:manager required +467ms
  plugin required command +469ms
  StatusChecker setting status checker +541ms
Error: The types definition file "/Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/database/webman-datamodel-2018-08-29-1415.graphql" could not be found.
    at /Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/src/PrismaDefinition.ts:295:15
    at Array.forEach (<anonymous>)
    at PrismaDefinitionClass.getTypesString (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/src/PrismaDefinition.ts:289:16)
    at PrismaDefinitionClass.<anonymous> (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/src/PrismaDefinition.ts:105:29)
    at step (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/dist/PrismaDefinition.js:32:23)
    at Object.next (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/dist/PrismaDefinition.js:13:53)
    at fulfilled (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-yml/dist/PrismaDefinition.js:4:58)
    at <anonymous>
Exiting with code: 1
I feel like I'm missing something / skipped over an important setup aspect by jumping straight to this tutorial
Also, is there a reason the tutorial doesn't recommend using
prisma init
?
Ah okay the datamodel file needs to be your graphql schema, duh
n
sorry @br tuned out for a bit. did you manage to follow through with this?
I have the feeling that there is something missing in the tutorial itself, it's not about you πŸ˜„
b
Hi @nilan unfortunately not πŸ™‚
( I also took the day off yesterday, so that's probably part of it πŸ˜‰ )
😁 1
n
Ok. Could you please describe your current progress and the problems you ran into? I'd love to improve the tutorial based on your feedback, and go through it again. An issue for this would be of great help: https://github.com/prisma/prisma/issues/new/choose πŸ™
b
Sure thing. As a totally from-zero new user there are lots of assumptions of pre-existing context. So here's where I got stuck where we left off: From the error output I posted above, in order to
prisma introspect
one has to have a types definition file (? I'm guessing this is a schema with the types only, not any of the Query/Mutation/Subscription definitions) ready in order to perform the introspection, even though that's missing that's entirely missing from the tutorial. The next obvious bit of context is "but what exactly is a datamodel file?"
I will create said issue but after I've actually been able to hook it up to my DB successfully
πŸ‘ 1
n
thanks. I'll keep an eye on this as well!
b
Copy code
brpro ➜  prisma-test git:(develop) βœ— prisma introspect
  config CWD /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config HOME /Users/br +2ms
  config definitionDir /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config definitionPath /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test/prisma.yml +0ms
  cli { isGlobal: true } +0ms
  StatusChecker setting status checker +0ms
  cli command id introspect +5ms
  cli:plugincache Got plugin from cache +0ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  cli:plugincache Got plugin from cache +1ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  plugins findCommand prisma-cli-core +0ms
  plugin requiring command +0ms
  cli-engine:plugins:manager requiring /Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core +0ms
  cli-engine:plugins:manager required +417ms
  plugin required command +419ms
  StatusChecker setting status checker +477ms
? What kind of database do you want to introspect? PostgreSQL
? Enter database host localhost
? Enter database port 5432
? Enter database user webman
? Enter database password
? Enter name of existing database webman_test
? Use SSL? No
? Enter name of existing schema public

Introspecting database... !
Error: Connection terminated by user
    at Client.end (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/pg/lib/client.js:402:36)
    at Timeout._onTimeout (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-db-introspection/src/connectors/PostgresConnector.ts:25:19)
    at ontimeout (timers.js:458:11)
    at tryOnTimeout (timers.js:296:5)
    at Timer.listOnTimeout (timers.js:259:5)
Exiting with code: 1
context:
Copy code
psql -U webman -d webman_test
psql (10.5)
Type "help" for help.

webman_test=> \dt

                       List of relations
 Schema |                Name                 | Type  | Owner
--------+-------------------------------------+-------+--------
 public | audit_log                           | table | webman
 public | avatar_images                       | table | webman
 public | buddy_error_log                     | table | webman
 public | calendar_mappings                   | table | webman
 public | calendar_servers                    | table | webman
 public | call_favourites                     | table | webman
 public | call_history                        | table | webman
 public | call_me_blocked_ip_addresses        | table | webman
 public | call_me_chat_logins                 | table | webman
 public | call_me_cookies                     | table | webman
 public | call_me_generated_button            | table | webman
In other words, the database is running and exists on the same machine.
Meanwhile
Copy code
brpro ➜  prisma-test git:(develop) βœ— docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
d684e8e9003f        prismagraphql/prisma:1.15   "/bin/sh -c /app/sta…"   9 minutes ago       Up 2 seconds        0.0.0.0:4466->4466/tcp   prisma-test_prisma_1
Then I can't connect to the Postgres server on the docker instance
Copy code
brpro ➜  prisma-test git:(develop) βœ— docker ps
CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
b5d3bcc4970d        prismagraphql/prisma:1.15   "/bin/sh -c /app/sta…"   16 minutes ago      Up 16 minutes       0.0.0.0:4466->4466/tcp   prisma-test_prisma_1
3a1dc2357e7a        postgres                    "docker-entrypoint.s…"   16 minutes ago      Up 16 minutes       5432/tcp                 prisma-test_postgres_1
So, sure, the prisma service is deployed and working, but I can't add anything to the postgres database – neither a schema nor data.
OKAY, I have managed to get the prisma container up and connected to my own database. I know that the problem was, the container was continually restarting because the postgres connection was being denied. I know why, it's because of something minor in the docs which confused me. Discovered the problem by inspecting the docker logs for the container and comparing the my
docker-compose.yml
with the one generated by
prisma init
. Anyway, working now. output from
docker logs <container id>
to confirm:
Copy code
Obtaining exclusive agent lock...
Obtaining exclusive agent lock... Successful.
Deployment worker initialization complete.
Initializing workers...
Successfully started 1 workers.
Server running on :4466
Version is up to date.
[Metrics] No Prisma Cloud secret is set. Metrics collection is disabled.
[Metrics] No Prisma Cloud secret is set. Metrics collection is disabled.
Unfortunately introspection fails –
Copy code
brpro ➜  prisma-test git:(develop) βœ— prisma introspect
  config CWD /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config HOME /Users/br +2ms
  config definitionDir /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config definitionPath /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test/prisma.yml +0ms
  cli { isGlobal: true } +0ms
  StatusChecker setting status checker +0ms
  cli command id introspect +6ms
  cli:plugincache Got plugin from cache +0ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  cli:plugincache Got plugin from cache +4ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +1ms
  plugins findCommand prisma-cli-core +0ms
  plugin requiring command +0ms
  cli-engine:plugins:manager requiring /Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core +0ms
  cli-engine:plugins:manager required +487ms
  plugin required command +490ms
  StatusChecker setting status checker +558ms
? What kind of database do you want to introspect? PostgreSQL
? Enter database host localhost
? Enter database port 5432
? Enter database user webman
? Enter database password webman
? Enter name of existing database webman_test
? Use SSL? No
? Enter name of existing schema public

Introspecting database... !
Error: Connection terminated by user
    at Client.end (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/pg/lib/client.js:402:36)
    at Timeout._onTimeout (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-db-introspection/src/connectors/PostgresConnector.ts:25:19)
    at ontimeout (timers.js:458:11)
    at tryOnTimeout (timers.js:296:5)
    at Timer.listOnTimeout (timers.js:259:5)
Exiting with code: 1
even if I radically simplify my datamodel to something very basic (which does correlate with the actual postgres database User table (just only two fields/columns of it)):
Copy code
type User @pgtable(name: "User") {
  id: Int! @unique
  login: String!
}
Same result:
Copy code
brpro ➜  prisma-test git:(develop) βœ— prisma introspect
  config CWD /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config HOME /Users/br +5ms
  config definitionDir /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test +0ms
  config definitionPath /Volumes/cs/vadadev-new/admin-poc-graphql-serverless-august-2018/prisma-test/prisma.yml +0ms
  cli { isGlobal: true } +0ms
  StatusChecker setting status checker +0ms
  cli command id introspect +6ms
  cli:plugincache Got plugin from cache +0ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  cli:plugincache Got plugin from cache +1ms
  cli:plugincache /Users/br/Library/Caches/prisma/plugins.json +0ms
  plugins findCommand prisma-cli-core +0ms
  plugin requiring command +0ms
  cli-engine:plugins:manager requiring /Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-cli-core +0ms
  cli-engine:plugins:manager required +436ms
  plugin required command +439ms
  StatusChecker setting status checker +503ms
? What kind of database do you want to introspect? PostgreSQL
? Enter database host localhost
? Enter database port 5432
? Enter database user webman
? Enter database password webman
? Enter name of existing database webman_test
? Use SSL? No
? Enter name of existing schema public

Introspecting database... !
Error: Connection terminated by user
    at Client.end (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/pg/lib/client.js:402:36)
    at Timeout._onTimeout (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-db-introspection/src/connectors/PostgresConnector.ts:25:19)
    at ontimeout (timers.js:458:11)
    at tryOnTimeout (timers.js:296:5)
    at Timer.listOnTimeout (timers.js:259:5)
  util timed out +0ms
Exiting with code: 0
Connection terminated by user
is a terrible message. It's the sort of message that should occur if I had pressed <kbd>Ctrl</kbd>+<kbd>C</kbd>
Well, rolling a blank setup with
prisma init
, then configuring the
docker-compose.yml
file to point to my new database and include the necessary port forwarding to the postgres container, I was then able to use
pg_restore
to copy over the schema and data as a new database.
Now, after I had first done this,
prisma introspect
did actually work, finally.
It spat out a datamodel file, but that file was incompatible with
prisma deploy
(perhaps unsurprisingly), although with a helpful list of errors with the datamodel file.
I tried hacking this file a bit (e.g. changing all the
id
fields from
id: Int! @unique
to
id: ID! @unique
) to get
prisma deploy
to work. Eventually I just removed everything but one isolated table as a test, and that was deployable. Anyway, unfortunately
introspect
has returned to its usual behaviour of exiting as per above.
Repeating the process, again, running
prisma introspect
after restoring the data with
pg_restore
to the postgres container works, and it spat out a
datamodel-1535828107432.graphql
file.
Run introspect a second time, get the same timeout error failure:
Copy code
Introspecting database... !
Error: Connection terminated by user
    at Client.end (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/pg/lib/client.js:402:36)
    at Timeout._onTimeout (/Users/br/.nvm/versions/node/v9.4.0/lib/node_modules/prisma/node_modules/prisma-db-introspection/src/connectors/PostgresConnector.ts:25:19)
    at ontimeout (timers.js:458:11)
    at tryOnTimeout (timers.js:296:5)
    at Timer.listOnTimeout (timers.js:259:5)
Exiting with code: 1
Β―\_(ツ)_/Β―
Oh, I should also add that getting the generated application schema of my restored db via the post-hook in
prisma.yml
is working, too
n
Update, the tutorial has been improved and it should work for you now πŸ™‚