question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`db execute` cannot resolve SQLite file path from schema

See original GitHub issue

Bug 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

  1. Create a simple schema pointing to an SQLite file in the parent directory.
  2. Prepare SQL script that changes this database.
  3. 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"
    
  4. 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
livthomascommented, Mar 18, 2022

Thanks @tomhoule! I can confirm it works as expected now.

1reaction
tomhoulecommented, Mar 11, 2022

Hi @livthomas — the fix is merged, it will be in next tuesday’s release 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python cant find database if script is run from other file
The solution was related to the path of the SQLite database: Everylayer in the project has his own path to connect with the...
Read more >
Finding database file - SQLite Forum
I have provided a specific path, c:/My1stdb.db, run the page and still nothing. The database opens in memory and updated but is never...
Read more >
Android SQLite Database Example Tutorial - DigitalOcean
Android SQLite is a very lightweight database which comes with Android ... We define a DBManager class to perform all database CRUD(Create, ...
Read more >
Prisma CLI Command Reference
Run prisma db pull to turn your database schema into a Prisma schema. ... Inspects the current directory to find a Prisma schema...
Read more >
Debug your database with the Database Inspector
To run any query method in a DAO, click the Run SQLite statement in Database Inspector button next to its @Query annotation. Screenshot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found