How do I create a prisma migration with a dictionary data?

Viewed 968

I have some dictionary table in my DB schema. E.g. "EventType" whth fields "id" and "value".

This table have one row:

1    TypeOne

Can I create a prisma migration with sql?

INSERT INTO "EventType" (id, value) VALUES (2, 'TypeTwo')
1 Answers

All the prisma migration files are valid SQL so you can put any arbitrary SQL in your migration files and it will be added to your migration history.

This is what you have to do:

  1. Generate a new migration without applying it to the database with the --create-only flag.
npx prisma migrate dev --create-only
  1. Take a look at the generated migration.sql file and update it accordingly to add any new SQL statements.

  2. Apply the migrations npx prisma migrate dev

Important Note: Always make sure you apply the changes to migration.sql before applying it to your database. Modifying an already applied migration file will lead to a corrupt migration history.

Related