I followed the instructions here: https://www.prisma.io/docs/get-started/01-setting-up-prisma-existing-database-a003/ , to set up prisma with a local postgres db.
To reproduce ..
Follow the steps at the above link, until "prisma introspect".
Here is my docker-compse.yml
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.16
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
databases:
prismatest:
connector: postgres
host: 172.17.0.1
port: 5432
database: pgguide
schema: public
user: deleted
password: deleted
migrations: false
ssl: true
Docker logs:
{"key":"error/handled","requestId":"local:management:cjm88swb800020a947kk06psa","payload":{"exception":"com.prisma.deploy.schema.ProjectAlreadyExists: Service with name 'prisma-temporary-introspection-service' and stage 'prisma-temporary-test-stage' already exists","query":"mutation($input: AddProjectInput!) {\n addProject(input: $input) {\n clientMutationId\n }\n }","variables":"{\"input\":{\"name\":\"prisma-temporary-introspection-service\",\"stage\":\"prisma-temporary-test-stage\",\"secrets\":[\"prisma-instrospection-secret\"]}}","code":"4005","stack_trace":"com.prisma.deploy.schema.mutations.AddProjectMutation.validate(AddProjectMutation.scala:61)\n com.prisma.deploy.schema.mutations.AddProjectMutation.execute(AddProjectMutation.scala:26)\n com.prisma.deploy.schema.SchemaBuilderImpl.$anonfun$addProjectField$3(SchemaBuilder.scala:219)\n sangria.relay.Mutation$.$anonfun$fieldWithClientMutationId$3(Mutation.scala:41)\n sangria.execution.Resolver.resolveField(Resolver.scala:1024)\n sangria.execution.Resolver.resolveSingleFieldSeq(Resolver.scala:236)\n sangria.execution.Resolver.$anonfun$resolveSeq$2(Resolver.scala:216)\n scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:302)\n scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)\n scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)\n akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)\n akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)\n scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)\n scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)\n akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)\n akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)\n akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)\n akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\n akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\n akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\n akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)","message":"Service with name 'prisma-temporary-introspection-service' and stage 'prisma-temporary-test-stage' already exists"}}
prisma/1.17.0-beta.10 (linux-x64) node-v8.10.0
ubuntu 16.04, psql (PostgreSQL) 9.5.14
I have verified with pgadmin (in a docker container) that I can connect to that host and port. I think these lines from docker logs indicate that it can connect (but I'm not sure):
Obtaining exclusive agent lock...
Obtaining exclusive agent lock... Successful.
Deployment worker initialization complete.
Initializing workers...
Successfully started 1 workers.
Server running on :4466
😢 I’m experiencing this as well. @jamesmbowler Did you have any luck fixing it?
@jamesmbowler It seems to work when running in interactive mode:
% prisma introspect -i
I still receive the following error, but it does in fact generate a datamodel.
TypeError: Cannot read property 'datamodel' of undefined
at IntrospectCommand.<anonymous> (/snapshot/cli/node_modules/prisma-cli-core/src/commands/introspect/introspect.ts:113:40)
at step (/snapshot/cli/node_modules/prisma-cli-core/dist/commands/introspect/introspect.js:42:23)
...
I think these lines from docker logs indicate that it can connect
That's correct!
@jamesmbowler, I am confused, the actual error you're facing seems to be this:
Service with name 'prisma-temporary-introspection-service' and stage 'prisma-temporary-test-stage' already exists
Where are you experiencing connection errors?
@christopherstyles this looks like a different error, could you open a new bug report?
Facing this issue as well. First time running prisma introspect
gives me this error Could not connect to database. Prisma Config doesn't have any database connection
and you can find this from the docker logs:
Warning: Management API authentication is disabled. To protect your management server you should provide one (not both) of the environment variables 'CLUSTER_PUBLIC_KEY' (asymmetric, deprecated soon) or 'PRISMA_MANAGEMENT_API_JWT_SECRET' (symmetric JWT).
Second time running prisma introspect
gives the same database connection error. Then the docker logs are similar to what @jamesmbowler had.
Can also confirm that introspect
in interactive mode is working properly. The datamodel with timestamp is created but I'm also getting the same error @christopherstyles got. So the generation of the file works but writing that file to prisma.yml
is throwing the error.
Introspect works but If I have even simple one-to-many relationship in my existing postgres database the prisma deploy
command fails.
@jamesmbowler @christopherstyles @valstu I am not sure if you are all talking about the same issue, and I don't yet fully understand it. I can see three different errors you mentioned.
It would be great to have a minimal example for either of those errors, including step by step instructions for local reproduction. Without those, it's difficult to move forward with this issue.
I created simple example repo with steps to reproduce.
https://github.com/valstu/prisma-introspect-bug-example
prisma.yml
you will get following error TypeError: Cannot read property 'datamodel' of undefined
. You should be able to reproduce this as well with the repo I linked.Thanks a lot @valstu, I just confirmed both the bugs you mentioned using your reproduction (with a minor change).
We're looking into this soon.
Thanks, I just merged your PR to my repo.
Just a background information. I'm working on custom workflow where I would use Knex to handle database migrations and prisma introspect to handle the rest. This way I would get proper up/down migrations files that our project needs. This is when I bumped into this issue.
I'm seeing the same issue that @valstu describes. Has there been any progress on this issue?
I'm seeing the same issue for an Existing Database option. Both the 'prisma init' command & the conventional way described on the prisma website do not work for me. I'm at it since the past 2 days & have been pulling my hair due to this, i would like to request the team to kindly look into this issue.
1. docker-compose.yml :
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.18
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: postgres
host: host.docker.internal
port: 5433
database: testdb
schema: public
user: *
password: *
migrations: false
2. On running 'prisma introspect':
! Could not connect to database. Prisma Config doesn't have any database connection
Get in touch if you need help: https://www.prisma.io/forum/
To get more detailed output, run $ export DEBUG="*"
3. Running the 'prisma introspect -i' generates the datamodel with an error : " ! Cannot read property 'datamodel' of undefined"
4. After adding the datamodel generated from the above step & then running 'prisma deploy' :
ERROR: Whoops. Looks like an internal server error. Search your server logs for request ID: local:management:cjnfpcj7m000608090h7ud31g
{
"data": {
"deploy": null
},
"errors": [
{
"message": "Whoops. Looks like an internal server error. Search your server logs for request ID: local:management:cjnfpcj7m000608090h7ud31g",
"path": [
"deploy"
],
"locations": [
{
"line": 2,
"column": 9
}
],
"requestId": "local:management:cjnfpcj7m000608090h7ud31g"
}
],
"status": 200
}
Get in touch if you need help: https://www.prisma.io/forum/
To get more detailed output, run $ export DEBUG="*"
! 'ENAMETOOLONG': spawn ENAMETOOLONG
Get in touch if you need help: https://www.prisma.io/
5. Getting the logs from the docker container gives the following :
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.
Warning: Management API authentication is disabled. To protect your management server you should provide one (not both) of the environment variables 'CLUSTER_PUBLIC_KEY' (asymmetric, deprecated soon) or 'PRISMA_MANAGEMENT_API_JWT_SECRET' (symmetric JWT).
{"key":"error/handled","requestId":"local:management:cjnfouvth00020809k8t7jv3k","payload":{"exception":"com.prisma.deploy.schema.ProjectAlreadyExists: Service with name 'prisma-temporary-introspection-service' and stage 'prisma-temporary-test-stage' already exists","query":"mutation($input: AddProjectInput!) {\n addProject(input: $input) {\n clientMutationId\n }\n }","variables":"{\"input\":{\"name\":\"prisma-temporary-introspection-service\",\"stage\":\"prisma-temporary-test-stage\",\"secrets\":[\"prisma-instrospection-secret\"]}}","code":"4005","stack_trace":"com.prisma.deploy.schema.mutations.AddProjectMutation.validate(AddProjectMutation.scala:61)\\n com.prisma.deploy.schema.mutations.AddProjectMutation.execute(AddProjectMutation.scala:26)\\n com.prisma.deploy.schema.SchemaBuilderImpl.$anonfun$addProjectField$3(SchemaBuilder.scala:219)\\n sangria.relay.Mutation$.$anonfun$fieldWithClientMutationId$3(Mutation.scala:41)\\n sangria.execution.Resolver.resolveField(Resolver.scala:1024)\\n sangria.execution.Resolver.resolveSingleFieldSeq(Resolver.scala:236)\\n sangria.execution.Resolver.$anonfun$resolveSeq$2(Resolver.scala:216)\\n scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:302)\\n scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)\\n scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)\\n akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)\\n akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)\\n scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)\\n scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)\\n akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)\\n akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)\\n akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)\\n akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)\\n akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)\\n akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)\\n akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)","message":"Service with name 'prisma-temporary-introspection-service' and stage 'prisma-temporary-test-stage' already exists"}} Warning: Management API authentication is disabled. To protect your management server you should provide one (not both) of the environment variables 'CLUSTER_PUBLIC_KEY' (asymmetric, deprecated soon) or 'PRISMA_MANAGEMENT_API_JWT_SECRET' (symmetric JWT).
Warning: Management API authentication is disabled. To protect your management server you should provide one (not both) of the environment variables 'CLUSTER_PUBLIC_KEY' (asymmetric, deprecated soon) or 'PRISMA_MANAGEMENT_API_JWT_SECRET' (symmetric JWT).
java.util.NoSuchElementException: None.get
at scala.None$.get(Option.scala:349)
at scala.None$.get(Option.scala:347)
at com.prisma.shared.models.FieldTemplate.build(Field.scala:78)
at com.prisma.shared.models.Model.$anonfun$fields$1(Model.scala:32)
at scala.collection.immutable.List.map(List.scala:287)
at com.prisma.shared.models.Model.fields$lzycompute(Model.scala:32)
at com.prisma.shared.models.Model.fields(Model.scala:32)
at com.prisma.shared.models.Schema.$anonfun$allFields$1(Schema.scala:16)
at scala.collection.immutable.List.flatMap(List.scala:335)
at com.prisma.shared.models.Schema.<init>(Schema.scala:16)
at com.prisma.deploy.migration.inference.SchemaInferrerImpl.infer(SchemaInferrer.scala:41)
at com.prisma.deploy.migration.inference.SchemaInferrer$$anon$1.infer(SchemaInferrer.scala:27)
at com.prisma.deploy.schema.mutations.DeployMutation.$anonfun$internalExecute$3(DeployMutation.scala:56)
at org.scalactic.Good.map(Or.scala:1207)
at com.prisma.utils.future.FutureUtils$FutureOr$.$anonfun$map$2(FutureUtils.scala:117)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:287)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:40)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Prisma is an amazing tool that is helping us newbie developers ease into the graphql world & i'd like to thank the developers for that.
I'd be highly grateful of even a response or a potential solution to this issue.
Thank You.
I experienced similar issues to @jamesmbowler @christopherstyles and @valstu.
I ended up running prisma introspect -i
which in turn created a file datamodel-1539977549306.prisma
.
According to the docs , "you need to rename the file to datamodel.prisma because that's the file name you specified in prisma.yml", even though the docs don't say to add datamodel
to the file.
#prisma.yml
endpoint: http://localhost:4466
datamodel: datamodel.prisma
I did in fact rename the datamodel-1539977549306.prisma
file to datamodel.prisma
. This takes care of the "TypeError: Cannot read property 'datamodel' of undefined"
Then ran prisma deploy
and everything worked.
I did not run into this issue:
"Introspect works but If I have even simple one-to-many relationship in my existing postgres database the prisma deploy command fails."
Hope this helps.
After upgrading to prisma-1.19, I am still receiving the same error when running prisma introspect
$ prisma introspect
â–¸ Could not connect to database. Prisma Config doesn't have any database connection
When running prisma introspect -i
, I have better luck
$ prisma introspect -i
? What kind of database do you want to introspect? PostgreSQL
? Enter database host localhost
? Enter database port 1234
? Enter database user user
? Enter database password password
? Enter name of existing database prod_device
? Use SSL? No
? Enter name of existing schema public
? Please select the Postgres schema you want to introspect public
Introspecting schema public 1.2s
Created datamodel definition based on 6 database tables.
Created 1 new file: GraphQL SDL-based datamodel (derived from existing database)
datamodel-1540392982596.prisma
â–¸ Cannot read property 'datamodel' of undefined
This also makes sense considering #3354 is still a WIP. Just wanted to keep this thread up to date.
I also faced this problem.
! Could not connect to database. Prisma Config doesn't have any database connection
Use -i
as a solution.
Btw, based on the prisma introspect -i
prompt:
? Enter database host localhost
Because I set db address other than localhost in docker-compose.yml
, I suspect it is the reading environment: PRISMA_CONFIG
problem of docker-compose.yml
.
I'm also experiencing issues with this. The "solutions" presented so far are working for me though (use prisma introspect -i
and manually set datamodel: datamodel.prisma
in prisma.yml
. Wow, it's so beautiful after it works though, so beautiful.
This is partially fixed in beta version 1.25.0-beta.12
. Please give it a go via npm install -g prisma@beta
and let me know if that works for you. Thanks.
The part that is fixed is throwing the following error TypeError: Cannot read property 'datamodel' of undefined
in interactive introspection.
We will keep this issue open and fix the other half shortly.
@divyenduz
I tested introspection today, and everything seems to be working fine as we recently did some introspection fixes.
Most helpful comment
After upgrading to prisma-1.19, I am still receiving the same error when running
prisma introspect
When running
prisma introspect -i
, I have better luckThis also makes sense considering #3354 is still a WIP. Just wanted to keep this thread up to date.