docs/1.27/datamodel-and-migrations/migrations-MYSQL-asdf.mdx
import Warning from 'components/Markdown/Warning'
export const meta = { title: "Migrations (MySQL)", position: 240, articleGroup: "Migrations", technology: "mysql", technologyOrder: 2, }
When using Prisma with a MySQL database, all your database migrations are performed using the prisma deploy command of the Prisma CLI.
There are two steps to every database migration:
prisma deploy to apply the changes and perform the migration of the underlying databasePrisma uses temporary directives to perform one-time migration operations. After deploying a service that contain a temporary directive, a temporary directive needs to be manually removed from the type definitions file.
The temporary directive @rename(oldName: String!) is used to rename a type or a field of a type.
If the @rename directive is not used, Prisma deletes old type/field before creating the new one, resulting in loss of data!
Renaming a type
Here is an example scenario:
type Post {
text: String
}
Rename the Post type to Story
@rename directive# renaming the `Post` type to `Story`
type Story @rename(oldName: "Post") {
text: String
}
prisma deployAfter having the saved the datamodel file with these changes, you need to run:
prisma deploy
@rename directive manuallytype Story {
text: String
}
Renaming a field
Here is an example scenario:
type Post {
text: String
}
Rename the text field to content
@rename directive# renaming the `text` field to `content`
type Post {
content: String @rename(oldName: "text")
}
prisma deployAfter having the saved the datamodel file with these changes, you need to run:
prisma deploy
@rename directive manuallytype Post {
content: String
}
@relation directive.