Moving to a monorepo | LiteFS and Prisma

Hi everyone,

In the past my app used the following template Epic Stack with the following essential config for the deployment to Fly.io

Dockerfile
fly.toml
litefs

I SSH’ed into the production VM (before the monorepo setup) and I saw that somehow a data.db file gets created in the ./prisma folder at the root.

While I was moving the app into a monorepo I was asking myself: how and why? I had quite some problems and struggles make a monorepo work and in no way I got a data.db inside the Prisma folder generated. I had to change a bunch of files and ENV variables in order to get a connection.

What I have done now is:

fly.toml

[mounts]
source = "litefs"
destination = "/var/lib/litefs"

[build]
dockerfile = "/other/Dockerfile"
ignorefile = "/other/Dockerfile.dockerignore"

litefs.yml

fuse:
  dir: '${LITEFS_DIR}'
data:
  dir: '/var/lib/litefs'

exec:
  - cmd: npx prisma migrate deploy --schema ./apps/sitenu/prisma/schema.prisma
    if-candidate: true

  # Main database WAL
  - cmd: sqlite3 /litefs/data/sqlite.db "PRAGMA journal_mode = WAL;"
    if-candidate: true

  # Cache database WAL
  - cmd: sqlite3 /litefs/data/cache.db "PRAGMA journal_mode = WAL;"
    if-candidate: true

  - cmd: npm start --prefix apps/sitenu

Dockerfile

I had to change the ENV to:

DATABASE_URL: file:/litefs/data/sqlite.db
DATABASE_PATH: /litefs/data/sqlite.db
CACHE_DATABASE_PATH: /litefs/data/cache.db
LITEFS_DIR: /litefs/data

While I had:
DATABASE_URL: file:/litefs/data/sqlite.db
DATABASE_PATH: ./prisma/data.db
CACHE_DATABASE_PATH: ./other/cache.db
LITEFS_DIR: /litefs/data

Is this setup correct or did I miss something in order to get the data.db file get created in the prisma folder? I should note that first when I ssh’ed into the VM my whole project was available within #app. Now with the monorepo the actual app is att #app/apps/projectname

Hi… This version looks correct, although I don’t know the details of Epic Stack, per se. The app should always access the database via the FUSE mount, which your litefs.yml does declare to be $LITEFS_DIR. Generally, I would use absolute paths (i.e., /something rather than ./something) for environment variables such as these, since the working directory (the initial . in ./prisma/data.db) that the app actually runs in is not always easy to deduce.

Quite possibly I’ve misunderstood your overall question, though… Are things working now, and you’re just wondering why it was previously failing?

Yes exactly! It is working but instead of saying: “heey it works, thats it” I was curious about how and why.

Thanks for the clarification!

1 Like