Can i share a schema with multiples container
# orm-help
m
Can i share a schema with multiples container
h
By "schema" you are referring to the graphql server schema or prisma datamodel?
m
datamodel
h
You mean you will need to import a few types from the datamodel of service 1 to datamodel of service 2 @Martin Benjamin If that's it you can do it by splitting your datamodel into multiple files and maintaining a shared file which both of your services can consume.
m
My problem is the following: if I create a schema in container 1 and run prisma deploy, it will destroy the schema in container 2, NORMAL. So I would like to create a schema in the prisma container that I share with the other two services.
but i dont know how...
h
services are isolated, why do you think it will destroy service 2?
m
because this the same prisma container(server)
I would like to be able to launch "prisma deploy" in the prisma container and be able to export the generated schema with the service one and service two
h
Prisma container is stateless, /backend/dev is completely isolated from /backend/prod in prisma server. They are mapped to a different database in the database.
you will need to run
prisma deploy
separately
as it will perform database ops like table creation etc
m
yeah, but when i run prisma deploy in service one
it overwrites the other schemas
I'll retry
h
it will not unless you run prisma deploy in second.
sharing datamodel is like sharing database table structure
prisma deploy
performs the migration. It will adjust the table structure.
So the structure of the internal database will not change unless you run prisma deploy
m
Yes, but i have two differents schema
in each service
message has been deleted
h
ok, then you will need to duplicate this. There is no current way of extending a type
m
i need to duplicate same schema in each container ?
h
each container is a separate service?
mean serving different apps?
m
each service is docker container
h
oh ok you mean, they are node servers running prisma client?
yes
i have 3 containers
one for prisma
one for service one
et another one for service two
h
ok, and you want to share graphql schemas, you are using nexus or simply graphql-tools
or typegraphql
I misunderstood you till now , 😅
m
No problem, i'm bad in english
🙂
i want to be able to perform queries like that
prisma.createUser({})
in service one
for example
h
both services consumes different data?
m
yes
service one is for user
h
ok, got it\
m
service two is for products
h
you want to share same prisma server between these services?
m
yes
h
but with different data source 🙂
m
What's the best way
?
different source ?
or same schema in prisma container ?
l
Hello Martin, so you’re trying to connect with a Prisma server from multiple service containers?
m
exact
h
ok
You can
/app/user
and
/app/post
in the same prisma container
see
Learn more about the endpoints of Prisma services
section here
@Martin Benjamin tables will be in same database
like
User
and
Post
or those will be isolated
m
thx @Harshit for your patience :d
l
From what I’ve understood, what you’re trying to do doesn’t sound right. I think the approach you chose is taking microservices one,
is this right?
And you still want the database to be a single source
m
yeah yeah
l
that doesn’t sound right for me, cuz basically and ideally a microservice has its own database, which means you need TWO Prisma server.
m
oh no 😞
l
each microservice has its own database
this is the right approach you need to take if you really need
h
but you can use a single prisma instance for a single database server, that will have multiple database
like you have MySQL 5.7 instance
l
And it’s not related to Prisma as you already knew.
h
/app/user will be mapped to app@user database
/app/post will be mapped to app@post
m
ok, one instance of prisma
h
speaking in terms of prisma
m
and miltiple database
?
h
and miltiple database
in the same database server
This part is important
l
I guess you don’t need to separate your schema or database
as harshit said, just use a single database with a single Prisma container
why would you like to separate the database?
m
do you have an example ,
?
h
the term database is confusing here as well. like we have a MySQL database server which can have thousands of databases
l
do you mean thousands of TABLES?
h
and one prisma instance can manage them all, that is how we run the demo servers.
do you mean thousands of TABLES?
no
l
oh
got it,
h
I mean separate databases within the same database server.
l
got it and Prisma already supports multiple database connection with a single Prisma server, is that right?
so one prisma server, multiple databases for microservices
right?
h
not database server connections, let me explain this more throughly.
l
please go ahead
h
Let's say you have a MySQL 5.7 instance
it is one database SERVER
l
yup
h
which prisma can make a connection to with ADMIN writes
we can make multiple databases in it now which can have multiple tables
note database server is different from database
so using the endpoint point property of prisma.yml
let's say our prisma instance is hosted at http://foo.bar
you can map two prisma services to two separate databases within the same database server
will be mapped to
backend@app1
in the MySQL instance
and http://foo.bar/backend/app1 will be mapped to
backend@app2
completely isolated from each other
m
can u have example @Harshit
?
where i define that
?
in prisma.yml
h
see here
m
?
h
these all are separate databases in the same database server managed by 1 prisma instance @Lukas
@Martin Benjamin
just defined separate prisma.yml files for your services
like you prisma instance is hosted at localhost:4466
prisma.yml no 1
Copy code
endpoint: <http://localhost:4466/serviceone/dev>
datamodel: datamodelfors1.prisma
prisma.yml no 2
Copy code
endpoint: <http://localhost:4466/servicetwo/dev>
datamodel: datamodelfors2.prisma
m
hmmm i define prisma.yml in service one and prisma.yml and service 2
right ?
h
yup
m
OK I SEE
ohhh fantastic
h
it will use same database server
but different databases within it
l
yeah that’ what I understood, thanks
h
@nikolasburk I didn't find much resources on services and stages in the docs. Can we add that?
l
I didn’t know Prisma support multiple database manangement in a single container
🙂 1
h
that is result of prisma being born out of graph.cool
using this architecture we use to managed all of the GCF instance in aurora instance. Each separate from each other.
m
It's work
🙌 1
amazing
thx man
hm, it's seems the solution don't create two differents db, but two differents tables
Copy code
endpoint: http://${env:PRISMA_HOST}:${env:PRISMA_PORT}/booking-service/dev
datamodel: datamodelBooking.prisma`
that for service one
Copy code
endpoint: http://${env:PRISMA_HOST}:${env:PRISMA_PORT}/auth-service/dev
datamodel: datamodelAuth.prisma
and that for service two
message has been deleted
ok i found
it's work just with mysql
no postgres 😞
h
@Martin Benjamin It is with postgres as well
It will create different schemas in postgres
If you are using table plus, you can switch the schema from the bottom left hand corner
m
Ok, i’ll try
Thx