Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to migrate a database programmatically? prisma

Tags:

prisma

I'm planning to create a secondary database for testing purposes. As of now I'm using Prisma's Client to perform CRUD to my secondary database. Good thing it worked fine.

My problem is the migration part. I still need to do it manually. Like editing the schema.prisma file, change the database url, and run prisma migrate dev manually.

I already browsed to Prisma's github, but I can't find an exact solution. I would like to ask here, maybe someone has an idea on how to achieve it.


Working code below.

import { PrismaClient } from '@prisma/client'

const prisma = new PrismaClient({
  datasources: {
    db: {
      url: 'postgresql://capstone:capstone@postgres:5432/blogpost_test?schema=public'
    }
  }
})

export default prisma

I expect something like below, in which we can just migrate the database programmatically??

prisma.$migrate or prisma.migrate()
like image 840
schutte Avatar asked Oct 26 '25 02:10

schutte


1 Answers

This is not directly supported by Prisma. There is an open feature request that you could +1 here.

Best workaround for now would be to writes scripts that use the CLI commands.

like image 183
Austin Crim Avatar answered Oct 28 '25 03:10

Austin Crim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!