Hey :wave: I’ve been using Prisma for a few weeks...
# orm-help
h
Hey 👋 I’ve been using Prisma for a few weeks and I absolutely love it but I have a question I’ve not been able to find a solution for in the docs - I need the ability to write a custom migration for certain fields. I have a URL stored in my database that points directly to an AWS S3 object and I wish to transform it to a new URL so that I may cache the files. Here’s an example of my schema
Copy code
type Document {
    id: ID! @unique
    title: String!
    cloudUrl: String! # <http://my-app.amazon.aws.com/ITEM_ID|my-app.amazon.aws.com/ITEM_ID> for example
    localUrl: String! # I'm adding this. I want to migrate it to <http://files.my-app.com/ITEM_ID|files.my-app.com/ITEM_ID>
}
I guess I’m just looking for a way to run a custom migration script as part of the deployment process.
w
AFAIK, there is no ‘official’ way to script a migration for now. This is being discussed in the #migrations channel. Your only option for now is to script that migration yourself . You could for example bootstrap a separate ‘project’ (that could be used as a boilerplate for other scripted migrations in the future), where you instantiate an instance of a
PrismaBinding
linked to your GraphQL API, and then use all the power of javascript to do whatever you want. eg:
const documents = await binding.query.documents({ where: { cloudUrl_not: null })
, then `await Promise.all(documents.map(document => binding.mutation.updateDocument({ where: { id: document.id }}, data: { localUrl:
<http://files.my-app.com/${document.id}|files.my-app.com/${document.id}>
} })))`