3 ms·
Tell HN: Prisma Is Great Now
So just now I had to make a migration to add a new table between two other tables that previously were joined with each other in a fairly early stage app I'm building.
I already had data in the tables and another dev working on it now, so I didn't want to nuke the database. So I got prisma to make the first migration (which it autogenerates from the new prisma schema file).
It warned me that it couldn't "just do this", because the existing data would be left with empty foreign keys, but that I could do the "just make the migration" step and not run it yet.
So I did that, opened the migration file. I changed the FK column to have a default of 0 where it was added. Then I got chatGPT to make me a SQL data migration to create default entries in the new table for each org (we're multi-tenant), then link the other table to the new default. Which was almost a stored proc in its own right.
Then I took a deep breath and told prisma to run the migration.
Pleasantly surprising: the schema+data migration ran successfully...
Extra nice bonus:
Prisma automatically made another new migration to cleanup the FK column by removing the DEFAULT!
(The kind of thing you usually need to remember to do after a migration like this, but could be forgiven for forgetting)
I mean, it's just doing its usual thing really, keeping the db schema in sync with the prisma schema, but the whole thing was pretty pleasant DX for what can be a nerve wracking thing to do.
It's a really solid and mature library, as ORM's go I can really recommend it.