不支持的数据库功能(Prisma Migrate)
Prisma Migrate 使用 Prisma 架构来确定要在数据库中创建哪些功能。然而,一些数据库特性 无法在 Prisma 架构中表示,包括但不限于:
¥Prisma Migrate uses the Prisma schema to determine what features to create in the database. However, some database features cannot be represented in the Prisma schema , including but not limited to:
-
存储过程
¥Stored procedures
-
触发器
¥Triggers
-
意见
¥Views
-
部分索引
¥Partial indexes
要将不受支持的功能添加到数据库中,你必须在应用该功能之前 定制迁移 包含该功能。
¥To add an unsupported feature to your database, you must customize a migration to include that feature before you apply it.
Prisma 模式能够表示 不支持的字段类型 和 原生数据库函数。
¥The Prisma schema is able to represent unsupported field types and native database functions.
自定义迁移以包含不受支持的功能
¥Customize a migration to include an unsupported feature
要自定义迁移以包含不受支持的功能:
¥To customize a migration to include an unsupported feature:
-
使用
--create-only
标志生成新的迁移而不应用它:¥Use the
--create-only
flag to generate a new migration without applying it:npx prisma migrate dev --create-only
-
打开生成的
migration.sql
文件并添加不支持的功能 - 例如,部分索引:¥Open the generated
migration.sql
file and add the unsupported feature - for example, a partial index:CREATE UNIQUE INDEX tests_success_constraint
ON posts (subject, target)
WHERE success; -
应用迁移:
¥Apply the migration:
npx prisma migrate dev
-
将修改后的迁移提交到源代码管理。
¥Commit the modified migration to source control.