How to handle Schema changes with Prisma?

Is there some established process to handle schema changes (i.e. user has first name + last name, but now we want to add the 'fullName' attribute for some reason)? In this example we would need to run a migration job, which iterates over all the existing users, and adds the new field. But where would we run this job? Are there some guidelines / tips?
7 Replies
Neto
Neto2y ago
You can add the full name as a nullable Run the script to merge the names Drop the name columns and make fullname non nullable Your issue isn't related to prisma only Not related to prisma, but with raw query you can merge the fields without using a prisma seed file
jonnyfapson
jonnyfapson2y ago
Thanks for the tip, this is what I imagined, too! Would you embed the merge script in the application code itself, or just run it via the db url, for example from your local computer?
Neto
Neto2y ago
with something like
Neto
Neto2y ago
Prisma
Seeding your database
Learn how to seed your database using Prisma's integrated seeding functionality and Prisma Client
Neto
Neto2y ago
create field update code to use the field move from the columns to new column (seed file) drop the two columns
Leonidas
Leonidas2y ago
To safely migrate your production database i recommend a multi-stage-process called the expand and contract pattern. Here is a great resource: https://www.prisma.io/dataguide/types/relational/expand-and-contract-pattern
Prisma's Data Guide
Using the expand and contract pattern | Prisma's Data Guide
In this article, we introduce the expand and contract pattern to help migrate data and clients to a new schema.
jonnyfapson
jonnyfapson2y ago
Thanks a lot! I will gladly checkout your suggestions!
Want results from more Discord servers?
Add your server