【Prisma】migrate devが「could not create the shadow database」とエラーになる
Error: P3014 Prisma Migrate could not create the shadow database. Please make sure the database user has permission to create databases. Read more about the shadow database (and workarounds) at https://pris.ly/d/migrate-shadow Original error: Error code: P1010 User `user` was denied access on the database `mydb`
Prismaでnpx prisma migrate dev
しようとすると、上記のエラーになった。
前提
version: '3.8'
services:
db:
container_name: db-container
image: mysql:5.7
environment:
MYSQL_DATABASE: mydb
MYSQL_ROOT_PASSWORD: root_pw
MYSQL_USER: user
MYSQL_PASSWORD: user_pw
ports:
- '3306:3306'
上記docker-compose.yml
の設定でMySQLのコンテナを立てており、user
ユーザーでDBに接続しマイグレーションを実行しようとした。
解決法
mysql -u user -p
grant CREATE, ALTER, DROP, REFERENCES ON *.* to 'user'@'%';
対象ユーザーにCREATE, ALTER, DROP, REFERENCES
の権限を付与する。これでマイグレーションが成功した。
公式ドキュメントにもある通り、マイグレーションでshadow databaseを作成する関係上、上記の権限が必要になるらしい。(そのためroleユーザーで接続していれば今回のエラーにはならない)