Prisma Creating New Database in MongoDB - mongodb

I've got Prisma connected to my MongoDB but when I make any mutations, a new database is being created in MongoDB called default_default and data is being added there instead of the database I specified when going through the setup here
https://www.prisma.io/docs/get-started/01-setting-up-prisma-existing-database-JAVASCRIPT-a003/
I'd expect the data to be saved in the database specified in the docker-compose.yml file
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.23
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: mongo
uri: 'mongodb://host.docker.internal:27017/my-db-name'
Has anyone experienced something similar and found a solution?
Thanks

This you do in prisma.config by setting endpoint:
endpoint: http://localhost:4466/graphql/default
This will use database graphq_default

Related

I need to dockerize my springboot application which has multiple datasources [duplicate]

I have a springboot application which uses a postgresql database and a mongoDB database , I have been able to correctly configure them but now when I want to dockerize my application to later deploy it on a Kubernetes cluster, I am completely clueless. Most of the youtube tutorials and articles are on how to dockerize simple springboot applications or springboot applications that use only one database, thus any input on how I can proceed to dockerize my application would be really appreciated!
Edit:
I am following this tutorial -
https://www.section.io/engineering-education/running-a-multi-container-springboot-postgresql-application-with-docker-compose/
Here in the docker-compose.yml file-
version: '3.1'
services:
API:
image: 'blog-api-docker.jar'
ports:
- "8080:8080"
depends_on:
PostgreSQL:
condition: service_healthy
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://PostgreSQL:5432/postgres
- SPRING_DATASOURCE_USERNAME=postgres
- SPRING_DATASOURCE_PASSWORD=password
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
PostgreSQL:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
Only one postgreSQL datasource is defined ,in my project with a similar postgreSQL datasource as given in the tutorial I am also using a mongoDB database which is running on atlas.
I am also including my application.properties file for your reference-
spring.ds-psql.datasource.jdbcUrl=jdbc:postgresql://localhost:5432/devicestatspsql
spring.ds-psql.datasource.username=
spring.ds-psql.datasource.password=
spring.data.mongodb.users-mongo-atlas.uri=*mongodb database url here*
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true
So I just need to know what changes are required in my docker-compose.yml file to accommodate this mongodb database in the docker image
You can use the Kubernetes Configmap and Secret as of now to store the configuration of your application.
Configmap and Secret are mostly for storing configurations like database connection strings, usernames, and passwords.
You can create different configuration maps as per requirement for Dev,Stag and Prod then inject the specific to your deployment so the application will get those values from either .env file or from OS environment.
Here's the reference article.

Cannot get Prisma to work with an existing MySQL DB that has data on it

First of all we have a MySQL DB setup on Heroku that already has data on it. I'm trying to add the Prisma layer on top of our DB.
My docker-compose.yml:
version: "3"
services:
prisma:
image: prismagraphql/prisma:1.34
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: mysql
host:
database:
user: user
password:
rawAccess: true
port: '3306'
migrations: false
Prisma.yml
# The HTTP endpoint for Prisma API
endpoint: http://localhost:4466
# Points to the file that contains your datamodel
datamodel: datamodel.prisma
# Specifies language and location for the generated Prisma Client
generate:
- generator: javascript-client
output: ./generated/prisma-client/
I go through prisma init and it connects to the DB and sets up the datamodel as it should, from what it seems like.
After docker-compose up -d I run prisma deploy and it hits me with
Could not connect to server at http://localhost:4466. Please check if
your server is running.
I run systemctl status docker and the docker is running as it should.
I then run docker-compose logs and I get back this
Exception in thread "main" java.sql.SQLSyntaxErrorException:
(conn=10044859) Access denied for user 'user'#'%' to database 'prisma'
So from reading around does prisma need the DB user to have the privileges to create a new schema in the DB for its management purposes?
I have no clue where to go from here. If I'm doing something wrong here, the help would be much appreciated!
Btw: SSL is not active on the DB so there is no need for it to be true.

FluentMySQL migration fails when building with docker-compose but not when building from Xcode

I'm getting the following crash when using docker-compose with Vapor & FluentMySQL.
api_1 | [ INFO ] Migrating 'mysql' database (/app/.build/checkouts/fluent/Sources/Fluent/Migration/MigrationConfig.swift:69)
api_1 | Fatal error: Error raised at top level: NIO.ChannelError.connectFailed(NIO.NIOConnectionError(host: "db", port: 3309, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIO.SingleConnectionFailure(target: [IPv4]db/172.27.0.2:3309, error: connection reset (error set): Connection refused (errno: 111))])): file /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-18_04/swift/stdlib/public/core/ErrorType.swift, line 200
Migration fails when using:
migrations.add(model: Model.self, database: .mysql)
If I remove that so no Models are migrated the app builds without errors and I am able to access it at http://localhost/.
My docker-compose.yml looks like this:
version: "3.7"
services:
api:
image: vaporapiimage
ports:
- 80:8080
environment:
MYSQL_HOST: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: dbname
SLEEP_LENGTH: 7
MYSQL_PORT: 3309
depends_on:
- db
db:
image: mysql:8.0.1
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: dbname
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- "3309:3306"
It builds and runs as expected locally from Xcode (as in without Docker).
If the api service is commented out then the db service will run on its own and create the database on first run.
Any help would be greatly appreciated.
UPDATE:
Replacing the api with Adminer results in being able to access the db through Adminer in the browser. So the db service is accessible and it seems as if the issue is with Vapor/Fluent (or rather my use of them):
admin:
image: adminer
ports:
- 8080:8080
The problem was that I had mapped the port for db to 3309 so that it didn't conflict with the host MYSQL but had also set the ENV 'MYSQL_PORT' to 3309 when that should have been kept as the default 3306 because that was for communication between containers.

How can i find Mongodb connection string for Prisma project?

I want to create a project using Prisma and i want to connect it to my local Mongodb database but i cant find the connection string it should be like this : http://user1:myPassword#localhost:27017/admin
If anyone knows how can i find my user and password.
You have to create the user in your mongodb server.
If you are using Prisma CLI, you can configure your database connection in the file docker-compose.yml,
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- '4466:4466'
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: mongo
uri: mongodb://http://user1:myPassword#localhost:27017/admin
database: mydb
Check this link for more info

Specific database details in docker-compose.yml file?

The service I'm using gives you a command to create a docker-compose file. You can then run docker-compose up and choose to create a new database.
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.8
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: mysql
host: mysql
port: 3306
user: root
password: prisma
migrations: true
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: prisma
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
This worked but now I need to set a second project with a new database. Even though I chose the option to set up a new database when I run my project I can see it's connecting to my old one:
prisma init
? Set up a new Prisma server or deploy to an existing server? Create new database
? What kind of database do you want to deploy to? MySQL
Created 3 new files:
prisma.yml Prisma service definition
datamodel.graphql GraphQL SDL-based datamodel (foundation for database)
docker-compose.yml Docker configuration file
Next steps:
1. Start your Prisma server: docker-compose up -d
2. Deploy your Prisma service: prisma deploy
3. Read more about Prisma server:
Is there something in my docker-compose.yml thats wrong? I belive default is the database name so I've tried the following but the same thing happens:
databases:
default2:
connector: mysql