How to migrate a database programmatically?
02:45 09 Jun 2022

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.

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.

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()

I already browsed Prisma's GitHub, but I can't find an exact solution.

prisma