Skip to content

v2 to v3 upgrade, difference in behavior in specifying sqlite database file location #2471

@sw34

Description

@sw34

Description and expected behavior
I am upgrading a zenstack v2 project to v3, using sqlite as the database. The behavior on how the database file location is determined has changed and that was not expected.

In my v2 app, in development:

  • my sqllite database was in the /prisma folder
  • I have a .env file with DATABASE_URL="file:./database.db".
  • my schema.zmodel is in the root folder, and specifies datasource db { provider = "sqlite" url = env("DATABASE_URL") }
  • My PrismaClient setup is located in /src/server/db.ts and did not specify a URL const createPrismaClient = () => new PrismaClient();

In v3, i moved schema.zmodel to the "/zenstack" folder. When I run zen db push, the database.db file is created in the /zenstack folder.

I my updated /src/server/db.ts if I don't specify a location for a sqlite file, database: new SQLite(), the table that should be there is not found [cause]: SqliteError: no such table: User

If I specify database: new SQLite(process.env.DATABASE_URL) I get a different error, this time SqliteError: unable to open database file

To make it work I need to specify the exact location of the database file database: new SQLite("file:../../zenstack/database.db")

The problem comes when I deploy this using docker, I have a docker volume that gets mapped to /data and I update my environment variable with that location, but my code now has a hardcoded location for the database.

Environment (please complete the following information):

  • ZenStack version: 3.4.5
  • Database type: sqlite
  • Node.js/Bun version: 22.19.15
  • Package manager: npm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions