Migrating data with prisma migrate

You can insert whatever sql statements you want in your migrations in order to also migrate data.

I added this after the generated schema migration

UPDATE "Product"
SET "parentId" = p.id
  SELECT id,
         variable_product_id AS v_p_id
  FROM "Product"
) AS p
WHERE parent_v_p_id IS NOT NULL
  AND p.v_p_id = parent_v_p_id;
1 Like

Nice tip on the --create-only flag, I hadn’t ever thought to modify the generated SQL before running a migration. I wonder if you could also use this technique to include some SQL commands to seed your database on the first migration.


Just add a bunch of INSERTs and you’re gtg