Prisma1: Prompt for database name when connecting to existing DB

Created on 25 Apr 2018  路  6Comments  路  Source: prisma/prisma1

Feature Request

What feature are you missing? Choosing database name when connecting to existing DB. As it is (at least in Postgres) it assumes the database is the same as the operating system user name. A safer assumption would be a prisma DB, but the user needs to be able to choose for various reasons.

How could this feature look like in detail? Tradeoffs? When running prisma init, and choosing Use existing database, the CLI should prompt for the database name in addition to the existing options, like host and port.

kinfeature arecli areconnectopostgres

Most helpful comment

Thanks for creating this issue, @frankdugan3. This feature will land in version 1.8 馃帀

All 6 comments

Thanks for creating this issue, @frankdugan3. This feature will land in version 1.8 馃帀

@schickling I followed the steps of using prisma v1.8 to connect to one existed database but It fails because it cannot connect to it. (the database is hosted in docker enviornment) I think it would be great if there is one example to implement it.

I tried with v1.9 and the prisma server failed to connect to an existing database, the database was on the local machine.
The prisma introspect to replace the datamodel came closer to being successful, but failed because of some errors in the generated datamodel. The prisma introspect issue is here

I am trying to connect Prisma to an existing database.

If I follow the prompts from prisma init, it fails to connect to the database and the prisma server is an endless restart loop (error pasted below). It may be worth noting, I can connect to the postgres database using psql -h localhost -p 5432 -U postgres

This is how my docker-compose.yml looks like

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.9
    restart: always
    ports:
    - "4466:4466"
    environment:
      PRISMA_CONFIG: |
        port: 4466
        # uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
        # managementApiSecret: my-secret
        databases:
          default:
            connector: postgres
            host: localhost
            port: 5432
            database: mydatabase
            user: postgres
            password: ''
            migrations: false

The error for the prisma restart is:

Jun 09, 2018 12:10:20 PM org.postgresql.Driver connect
SEVERE: Connection error: 
org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:245)

I can confirm that this is resolved in the latest Prisma CLI - npm install -g prisma. The command asks for the database name and persists it in docker-compose.yml file.

@Jaikant : In your case, it is not working because the docker container is not aware of localhost as a resolvable URL. You need to provide an accessible URI to it with a valid Postgres server. Think of it as a VM, and localhost makes the VM search internally while the Postgres server is running on the host machine. I hope this clears it for you. Thanks.

@divyenduz yes that makes sense, let me try it with an accessible URI.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dohomi picture dohomi  路  3Comments

sedubois picture sedubois  路  3Comments

MitkoTschimev picture MitkoTschimev  路  3Comments

akoenig picture akoenig  路  3Comments

Fi1osof picture Fi1osof  路  3Comments