`db execute` cannot resolve SQLite file path from schema
See original GitHub issueBug description
The new db execute
command (https://github.com/prisma/prisma/issues/11514) is not able to properly resolve the path to an SQLite file specified in prisma.schema
file. I have the url
set to file:../my.db
. It looks like it resolves this path as relative to the folder where db execute
is run and not to the folder where prisma.schema
file is located.
It only works if I set url
to file:./my.db
even though the actual DB file is in the parent directory. But this change breaks other scripts working with this file.
An easy workaround is to use --url
parameter instead of --schema
. But it would be better if I was able to use the schema file so there would only be a single source of truth for DB file location.
Another thing is that it is hard to detect this problem since the command doesn’t even fail but creates another DB file two levels up in the folder structure and says Script executed successfully
.
How to reproduce
- Create a simple schema pointing to an SQLite file in the parent directory.
- Prepare SQL script that changes this database.
- Execute the script using
db execute
command in the parent directory, e.g.:prisma db execute --preview-feature --schema prisma/schema.prisma --file "prisma/views/view1.sql"
- See that the DB file in the parent directory hasn’t been affected. Instead, the changes have been applied to a DB file that is located two levels up in the file system.
Expected behavior
Prisma db execute
command should resolve DB file path set in schema.prisma
file relative to the schema file folder and not to the folder where the command has been executed.
Prisma information
First lines of prisma/schema.prisma
file:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = "file:../my.db"
}
Environment & setup
- OS: Linux 4.19.225-1-MANJARO
- Database: SQLite
- Node.js version: v17.3.0
Prisma Version
prisma : 3.9.0
@prisma/client : 3.9.0
Current platform : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio : 0.457.0
Preview Features : interactiveTransactions
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
Thanks @tomhoule! I can confirm it works as expected now.
Hi @livthomas — the fix is merged, it will be in next tuesday’s release 😃