Are data migrations with Prisma (and more specific...
# orm-help
j
Are data migrations with Prisma (and more specifically for working with Planetscale) still unsupported? Comment from 4 months ago: https://prisma.slack.com/archives/CA491RJH0/p1647556028544079?thread_ts=1647490664.669059&cid=CA491RJH0 Existing issues: https://github.com/prisma/prisma/discussions/8933 https://github.com/prisma/prisma/issues/6345 This is an essential feature that’s seems like it’s still missing, what gives? What would a good workaround be? Just create javascript code in files in a prisma/migrations folder to migrate some data, and override the db url in
new PrismaClient()
to point to the db URL you want to run them on? It seems crazy to not have this when most other ORMs have this capability, at the very least it would be nice to have some documentation and examples for any potential solutions or workarounds instead of pointing users to old articles or other third-party solutions.
👀 1
1
The only thing useful I’ve found so far is to use
Copy code
npx prisma db execute --file ./script.sql --schema prisma/schema.prisma
for custom sql queries to help with data migrations but this is very limiting. Ideally you should be able to use PrismaClient to take advantage of the querying DSL along with any custom javascript code.
a
Hey Jeremy, You can definitely create a JavaScript file and instantiate and use the Prisma Client to accomplish your data migration needs. Regarding a more tight integration, we would love to hear your thoughts on how we could design such a feature in the future. The issues you linked would be a great place to leave feedback.
v
👋 hey @Jeremy Cohen Hoffing ! Did you have a chance to see Austin's comment? Let us know if you still have any questions or want to share any feedback!
j
@Vladi Stevanovic Hi, yes I saw @Austin’s comment. I will try to use the PrismaClient, I tried before but was having issues with referencing the PrismaClient dependency in this type of usage. Perhaps if Prisma can provide some documentation/examples on how to run a data migration and what the file/project structure looks like that would be awesome.
👀 1
n
Hey Jeremy 👋 I would recommend you to have a look at this typescript-starter repository. You can write your data migration script in main function of
script.ts
file and run the command
npm run dev
to execute the main function, this starter template has the boilerplate code already set up. You would only need to add your DATABASE_URL in the env file. I use this starter project often to run custom scripts. Do let me know in case you come across any issue.