drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.47k stars 486 forks source link

[BUG]: Drizzle doesn't use the schema part of a database connection URL #2449

Open adam-arold opened 3 weeks ago

adam-arold commented 3 weeks ago

What version of drizzle-orm are you using?

0.31.0

What version of drizzle-kit are you using?

0.22.1

Describe the Bug

I have the following DATABASE_URL in my .env file:

DATABASE_URL=postgresql://x:x@localhost:5433/x?schema=x

When I'm trying to run

npx drizzle-kit introspect

it incorrectly uses the public schema of my database (which is empty). I tried using --schemaFilter which I thought would solve this problem but I received a very lengthy Zod error instead of a human-readable error message. This blocks any further progress WRT to migrating to Drizzle as I can't generate the Drizzle types.

I checked and there is also no option to set a schema in the Drizzle config.

Expected behavior

Either url should be used correctly or I should be able to pass a schema field in the Config.

Environment & setup

VS Code / pnpm / the usual suspects

ferencbartok commented 3 weeks ago

I've also tried using introspect with --schemaFilter argument, but I always get path: [ 'schemaFilter' ], message: 'Invalid input'

I've tried --schemaFilter ["tables"] --schemaFilter 'tables' --schemaFilter "tables" and a few others, but none worked. How could I filter on schema when doing introspect?

Edit: part of the error message:

 "code": "invalid_type",
            "expected": "string",
            "received": "boolean",
            "path": [
              "schemaFilter"
            ],
            "message": "Expected string, received boolean"

Edit (2): I see that you can define "schemaFilter: 'tables'," in the config file, that seems to work. The CLI still seems to be bugged.