0

I'm migrating an existing TypeORM + PostgresQL project from TypeORM to Prisma. This existing project was handling migrations with Flyway: I wrote the SQL scripts to change the DB and those script were executed against de DB via Flyway. Now that I'm using prisma, I would like to take advantage of prisma migration. However, I would still like to have full control of the migrations, and to that extent, I would like to keep using Flyway. My idea was to generate the SQL files with prisma and then use Flyway to run them against de DB. What I've read so far, is that prisma cannot be used to just generate migrations (it will run them eventually, even if I use the --create-only flag, as discussed in here). I found in the help of prisma cli the prisma migrate diff command and I saw that it receives two urls to compare the schemas of two databases and generate de diff as an SQL file. I was wondering if there is something like prisma migrate diff that receives a url and a schema.prisma file so I can generate the diff using the url to my DB and my current schema file. Or is there any other way to just generate prisma migrations without executing them?

Now, that is what I would prefer. In case there is no way to just generate prisma migrations, I think it's fine to use it to run the migrations. However, I'm a little concerned on possible conflicts between the Flyway migrations that have been executed in the past and the new prisma migrations. I know both of them create tables in the DB to keep track of the migrations and Flyway's and Prisma's table should be different, so there should be no problems. But I don't feel confident about this. Has anyone migrate from Flyway to Prisma than can give me some advise on this? Or can I just ignore Flyway migrations.

Juan Chaves
  • 81
  • 1
  • 4

1 Answers1

1

 I was wondering if there is something like prisma migrate diff that receives a url and a schema.prisma file so I can generate the diff using the url to my DB and my current schema file

Yes. You can point prisma migrate diff to your Prisma schema as the "to" state and your DATABASE_URL as the "from" state as follows:

npx prisma migrate diff \
-—from-schema-datamodel ./prisma/schema.prisma   # path to your Prisma schema 
-—to-url $DATABASE_URL                           # enviroment variable 
-—script diff-migration.sql

You can then create a flyway migration using the generated SQL from prisma migrate diff.

You can learn more about the different arguments prisma migrate diff accepts in our CLI reference. Don't hesitate to let me know if you hit a snag. :)

Joël
  • 1,563
  • 1
  • 18
  • 31
Alex Ruheni
  • 989
  • 5
  • 6