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
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:
/prismafolderDATABASE_URL="file:./database.db".datasource db { provider = "sqlite" url = env("DATABASE_URL") }/src/server/db.tsand did not specify a URLconst 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/zenstackfolder.I my updated
/src/server/db.tsif 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: UserIf I specify
database: new SQLite(process.env.DATABASE_URL)I get a different error, this timeSqliteError: unable to open database fileTo 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
/dataand 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):