drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzlekit has mismatch of postgres configuration static type and actual validator

Open
#4,443 1 comment 0 reactions 0 assignees View on GitHub
bug drizzle/kit enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.39.3

### What version of `drizzle-kit` are you using?

0.31.0

### Other packages

_No response_

### Describe the Bug

First I must thank the team for this amazing project! It is a great typesafe version of SQL that facilitates a lot of typescript fullstacks.

I recently experienced passing the ssl configuration to our postgres driver using the `ssl` option works in the running server, but for `drizzle.config.ts` it failed in migration:

For simplicity, the case is like:

```bash
pnpm drizzle-kit migrate
```

```bash
applying migrations...error: no pg_hba.conf entry for host "***", user "postgres", database "***", no encryption
```

My `drizzle.config.ts`:

```
export default defineConfig({
schema: "./src/db/schema.ts",
out: "./db/migrations",
dialect: "postgresql",
dbCredentials: {
url: envs.DATABASE_URL,
ssl: {
ca: readFileSync(
"my-ca-bundle.pem",
'utf8',
),
rejectUnauthorized: true,
},
});

```

The typing is correct because the `Config` type clearly allows us to pass the `ssl` object into that part:

[The ssl type](https://github.com/drizzle-team/drizzle-orm/blob/df9ec8bb7155332251860f5e0586e2994b0f094b/drizzle-kit/src/index.ts#L149)

```ts
| {
dialect: Verify;
dbCredentials:
| ({
host: string;
port?: number;
user?: string;
password?: string;
database: string;
ssl?:
| boolean
| 'require'
| 'allow'
| 'prefer'
| 'verify-full'
| ConnectionOptions;
} & {})
| {
url: string;
};
}
```

However, the [PostgresCredentialConfig](https://github.com/drizzle-team/drizzle-orm/blob/626cc956102d3a62746390b44439e18e5fd090de/drizzle-kit/src/cli/validations/postgres.ts#L5) tells another story:

```ts
export const postgresCredentials = union([
object({
driver: undefined(),
host: string().min(1),
port: coerce.number().min(1).optional(),
user: string().min(1).optional(),
password: string().min(1).optional(),
database: string().min(1),
ssl: union([
literal('require'),
literal('allow'),
literal('prefer'),
literal('verify-full'),
boolean(),
object({}).passthrough(),
]).optional(),
}).transform((o) => {
delete o.driver;
return o as Omit;
}),
object({
driver: undefined(),
url: string().min(1),
}).transform<{ url: string }>((o) => {
delete o.driver;
return o;
}),
object({
driver: literal('aws-data-api'),
database: string().min(1),
secretArn: string().min(1),
resourceArn: string().min(1),
}),
object({
driver: literal('pglite'),
url: string().min(1),
}),
]);
```

It seems not passing the ssl field, other than the first case, where you need to specify `host, port, user...` so that the schema will take into the ssl field.

If my understanding is correct that they should be `1:1`, then the `dbCredentials` in `config` part should just use whatever type is generated by `postgresCredentials`. The mismatch causes unexpected ignored parameters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.