Skip to main content

Prisma Migrate 概述


info

不适用于 MongoDB
,请使用 db push 代替 migrate dev 及相关命令,用于 MongoDB

¥Does not apply for MongoDB
Instead of migrate dev and related commands, use db push for MongoDB.

Prisma Migrate 使你能够:

¥Prisma Migrate enables you to:

  • 随着 Prisma 架构 的发展,使你的数据库架构与它保持同步

    ¥Keep your database schema in sync with your Prisma schema as it evolves and

  • 维护数据库中的现有数据

    ¥Maintain existing data in your database

Prisma Migrate 生成 .sql 迁移文件的历史记录,并在 开发生产 中发挥作用。

¥Prisma Migrate generates a history of .sql migration files, and plays a role in both development and production.

Prisma Migrate 可以被认为是一种混合数据库模式迁移工具,这意味着它同时具有声明性和命令性元素:

¥Prisma Migrate can be considered a hybrid database schema migration tool, meaning it has both of declarative and imperative elements:

  • 声明式:数据模型在 Prisma 架构 中以声明性方式描述。Prisma Migrate 从该数据模型生成 SQL 迁移文件。

    ¥Declarative: The data model is described in a declarative way in the Prisma schema. Prisma Migrate generates SQL migration files from that data model.

  • 至关重要的:所有生成的 SQL 迁移文件都是完全可定制的。因此,Prisma Migrate 提供了命令式迁移工具的灵活性,使你能够修改迁移的执行内容和方式(并允许你运行自定义 SQL,例如利用原生数据库功能、执行数据迁移等)。

    ¥Imperative: All generated SQL migration files are fully customizable. Prisma Migrate hence provides the flexibility of an imperative migration tool by enabling you to modify what and how migrations are executed (and allows you to run custom SQL to e.g. make use of native database feature, perform data migrations, ...).

提示

如果你正在制作原型,请考虑使用 db push 命令 - 参见 使用 db push 进行架构原型设计 的例子。

¥If you are prototyping, consider using the db push command - see Schema prototyping with db push for examples.

有关 Prisma Migrate CLI 命令的详细信息,请参阅 Prisma 迁移参考

¥See the Prisma Migrate reference for detailed information about the Prisma Migrate CLI commands.