hi everyone! I’m trying prisma as a candidate for ...
# orm-help
a
hi everyone! I’m trying prisma as a candidate for orm in a project that’s being converted from php to node, and while the other, more traditional orm’s look like they are more “featured”, I really like prisma schema definition and the auto generated client. however, I’m not sure about couple of things that might be a huge showstoppers: 1. I couldn’t find anything related to data migrations in the docs, for example, how would one launch a process based on completed schema migration? the
prisma migrate
command generates raw sql file and there’s no
up
method that could be used to launch a custom script or whatever to initiate a data migration process related to the schema process. is there a best practices how to do that with maybe
prisma seed
or some other method, or do I need to figure out on my own how to do that? 2. are
UNION
queries available from the client api or only by raw sql? 3. is there a way to specify db master/replicas and set the query to use a
replica
for reads and
master
for writes? (like Mikro-ORM) Thanks!
n
Hey 👋 1. You could achieve up/down style migrations flow by Moving forwards and Moving Backwards through
migrate diff
and
db execute
commands which were introduced recently and are in preview. 2. As of now, Raw SQL would be the only way but we do have an existing Feature Request to support Union Query and Union Type 3. You can dynamically pass a connection string when instantiating a PrismaClient so you can have two clients in your app, one for reads and one for writes. Reference - Programmatically override datasource url
Copy code
const readClient = new PrismaClient({
  datasources: { db: { url: "xx-read-connection-string-xx" }}
})

const writeClient = new PrismaClient({
  datasources: { db: { url: "xx-write-connection-string" }}
})
a
Thank you for your reply, 1. Moving Forwards/Backwards seems to apply to schema changes and that’s not what I was looking for, so I will take it as there’s no way to have methods rather then sql changes. 2. That is unfortunate for me as I do need this feature as the product relies on union queries. 3. That sounds like a possible solution but I will have to think if that’s something we can use in this project… Thanks again!
j
What queries do you need to express that would use a UNION under the hood that Prisma can not express?