drizzle-team / drizzle-kit-mirror

Docs and issues repository for drizzle-kit
291 stars 17 forks source link

`drizzle-kit introspect` doesn't support correct `database` config path type #492

Open jakeisnt opened 1 month ago

jakeisnt commented 1 month ago

Docs everywhere for Drizzle suggest that database config field should be a string, like so:

https://orm.drizzle.team/docs/get-started-postgresql

const config = defineConfig({
  dialect: 'postgresql',
  out: './db/drizzle',
  schema: './db/drizzle/schema.ts',
  dbCredentials: {
    host: process.env.DB_HOSTNAME!,
    port: Number.parseInt(process.env.DB_PORT!, 10),
    user: process.env.DB_USERNAME!,
    password: process.env.DB_PASSWORD!,
    database: process.env.DB_NAME!,
  },
  // Print all statements
  verbose: true,
  // Always ask for confirmation
  strict: true,
});

but upon executing npx drizzle-kit introspect, I get this error (Node.js 20):

/Users/jake/Documents/improvin/pumbaa/node_modules/drizzle-kit/bin.cjs:5186
            const error2 = new ZodError(ctx.common.issues);
                           ^

_ZodError: [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "string",
    "path": [
      "database"
    ],
    "message": "Expected object, received string"
  }
]
    at get error [as error] (/Users/jake/Documents/improvin/pumbaa/node_modules/drizzle-kit/bin.cjs:5186:28)
    at _ZodObject.parse (/Users/jake/Documents/improvin/pumbaa/node_modules/drizzle-kit/bin.cjs:5266:22)
    at preparePullConfig (/Users/jake/Documents/improvin/pumbaa/node_modules/drizzle-kit/bin.cjs:20462:33)
    at async _Command.<anonymous> (/Users/jake/Documents/improvin/pumbaa/node_modules/drizzle-kit/bin.cjs:131691:7) {
  issues: [
    {
      code: 'invalid_type',
      expected: 'object',
      received: 'string',
      path: [ 'database' ],
      message: 'Expected object, received string'
    }
  ],
  addIssue: [Function (anonymous)],
  addIssues: [Function (anonymous)],
  errors: [
    {
      code: 'invalid_type',
      expected: 'object',
      received: 'string',
      path: [ 'database' ],
      message: 'Expected object, received string'
    }
  ]
}

The correct type of database according to the docs - and the code itself - is a string, but the Zod linting seems to prefer an object?

barrynorman commented 1 month ago

Same here. Suddenly...

tirth0 commented 1 month ago

I've been using mysql and the following change to the node_modules/drizzle-kit/bin.cjs has helped overcome this issue: On line 14581 I replaced:

database: objectType({
  prefix: prefix.optional().default("index")
}).optional()

with

database: stringType().min(1),

I'm using mysql dialect with TiDB.

barrynorman commented 1 month ago

@tirth0 This worked as a temp fix. Thanks so much. Still needs to be fixed though.

Johann-S commented 1 month ago

I downgrade to v0.22.8 and everything works fine 👌 Hope a fix will arrive soon 🙏

asolya commented 4 weeks ago

Same for my project as well.