Umami 使用 Vercel 构建时“✗ Command failed: prisma migrate deploy”

摘要:本文讨论了在使用 Vercel 构建 Umami 项目时遇到的错误。在部署过程中,执行 prisma migrate deploy 命令时发生错误,出现 P3009 错误,指出存在未解决的迁移问题。具体的迁移错误是名为 `05_add_visit_id` 的迁移失败。解决此问题需要解决数据库中的迁移问题,具体步骤包括修改 `package.json` 文件中的 `build-db` 命令,并运行 `prisma migrate resolve --applied '05_add_visit_id'` 命令来解决迁移冲突。该问题在 Vercel 和 Github 上的 Umami 项目中均有报道。

我的Umami从2.10.2拉取代码升级到2.11.3版本,Vercel在构建过程中发生以下错误:

Error: P3009
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `05_add_visit_id` migration started at 2024-05-07 00:34:36.162 UTC failed


✗ Command failed: prisma migrate deploy
Error: P3009
migrate found failed migrations in the target database, new migrations will not be applied. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
The `05_add_visit_id` migration started at 2024-05-07 00:34:36.162 UTC failed

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Command "yarn run build" exited with 1

定位到这些关键信息:Error: P3009​、05_add_visit_id​、✗ Command failed: prisma migrate deploy​。

经过互联网搜索后找到了这篇文章。按照文章操作之后发现无法成功,于是就看到了Github上的Issue

刚刚看到的文章也是从这个Issue里面整理出来的方法。再往下面翻就找到了前几周Vercel用户提供的解决办法。经过尝试后解决构建失败的问题🥰

解决方法

  1. 在Github仓库中打开package.json​文件

  2. 搜索"build-db": "npm-run-all copy-db-files build-db-client",

  3. 将其替换成

    "build-db": "npm-run-all copy-db-files build-db-client resolve-db",
    "resolve-db": "prisma migrate resolve --applied '05_add_visit_id'",