Why `prisma generate --sql` needs to have `DATABASE_URL`?

I'm getting this error when executing prisma generate --sql but not if executing prisma generate:
4.679 api:build: > prisma generate --sql
4.679 api:build:
5.545 api:build: Prisma schema loaded from prisma/schema.prisma
5.598 api:build: Error: Prisma schema validation - (get-config wasm)
5.598 api:build: Error code: P1012
5.598 api:build: error: Environment variable not found: DATABASE_URL.
5.598 api:build: --> prisma/schema.prisma:9
5.598 api:build: |
5.598 api:build: 8 | provider = "postgresql"
5.598 api:build: 9 | url = env("DATABASE_URL")
5.598 api:build: |
4.679 api:build: > prisma generate --sql
4.679 api:build:
5.545 api:build: Prisma schema loaded from prisma/schema.prisma
5.598 api:build: Error: Prisma schema validation - (get-config wasm)
5.598 api:build: Error code: P1012
5.598 api:build: error: Environment variable not found: DATABASE_URL.
5.598 api:build: --> prisma/schema.prisma:9
5.598 api:build: |
5.598 api:build: 8 | provider = "postgresql"
5.598 api:build: 9 | url = env("DATABASE_URL")
5.598 api:build: |
Why does --sql need to connect to the DB? May I disable it?
1 Reply
Prisma AI Help
You've gone full bot mode! Let me fetch that AI answer for you ASAP. The prisma generate --sql command requires the DATABASE_URL environment variable because it needs an active database connection to generate the TypedSQL functionality. This is a new feature in Prisma that allows for type-safe raw SQL queries. According to the TypedSQL documentation:
TypedSQL requires an active database connection to parse the SQL and return type information. This means that you need to have a running database when generating the Prisma Client with TypedSQL enabled.
This requirement is causing issues for users who want to run prisma generate in environments where they don't have a running database, such as in CI/CD pipelines or during the build process. Unfortunately, there's currently no way to disable this requirement when using the --sql flag. However, there are a few workarounds you can consider: 1. Provide a valid DATABASE_URL during the build process. 2. Generate the Prisma Client without the --sql flag in your CI/CD environment. 3. Generate the Prisma Client with --sql locally and commit the generated files to your repository. The Prisma team is aware of this limitation and there's an open issue discussing potential solutions: Remove requirement for a running database when using TypedSQL. For now, if you don't need the TypedSQL functionality in your build environment, you can simply use prisma generate without the --sql flag to avoid this error.

Did you find this page helpful?