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
24.62k stars 650 forks source link

[BUG]: Cannot destructure property 'resourceArn' of 'connection' as it is undefined #3224

Open L-Mario564 opened 3 weeks ago

L-Mario564 commented 3 weeks ago

What version of drizzle-orm are you using?

?

What version of drizzle-kit are you using?

?

Describe the Bug

From drizzle-kit-mirror repo.

https://github.com/drizzle-team/drizzle-kit-mirror/issues/605

Hello,

When trying to run the studio, with AWS data-api postgres, i'm getting the following

Error:

TypeError: Cannot destructure property 'resourceArn' of 'connection' as it is undefined.

I think the bug has been introduced in this commit, drizzle-team/drizzle-orm@6f4fc4c#diff-b89d8d3caa6777e0a8c2194727aa2978387676f9b659726d5f91d5e365dd655fR124

aws-data-api/pg driver.ts

Connection param seems to come from the new API of drizzle, maybe it has not been propagated to drizzle.config.ts for the data-api ?

Thanks

https://github.com/drizzle-team/drizzle-kit-mirror/issues/606

wisedan@ML-N96CF5J61F bestrev_backend % npx drizzle-kit migrate
No config path provided, using default 'drizzle.config.ts'
Reading config file '/Users/wisedan/bestrev/bestrev_backend/drizzle.config.ts'
db name -----
resourceArn arn:aws:rds:-----------
secretArn arn:aws:secretsmanager:---------
**TypeError: Cannot destructure property 'resourceArn' of 'connection' as it is undefined.**
    at drizzle (/Users/wisedan/bestrev/bestrev_backend/node_modules/src/aws-data-api/pg/driver.ts:171:10)
    at preparePostgresDB (/Users/wisedan/bestrev/bestrev_backend/node_modules/drizzle-kit/bin.cjs:64043:22)
    at async Object.handler (/Users/wisedan/bestrev/bestrev_backend/node_modules/drizzle-kit/bin.cjs:87123:39)
    at async run (/Users/wisedan/bestrev/bestrev_backend/node_modules/drizzle-kit/bin.cjs:85613:7)

drizzle.config.ts

import 'dotenv/config';

import { defineConfig } from 'drizzle-kit';

console.log(process.env.RDS_DB_NAME);
console.log(process.env.RDS_DB_CLUSTER_ARN);
console.log(process.env.RDS_DB_SECRET_ARN);

export default defineConfig({
  dialect: 'postgresql',
  dbCredentials: {
    // url: process.env.DATABASE_URL || 'no-database-url-set',
    database: process.env.RDS_DB_NAME || 'no-database-name-set',
    resourceArn: 'no-cluster-arn-set',
    secretArn: process.env.RDS_DB_SECRET_ARN || 'no-secret-set',
  },
  driver: 'aws-data-api',
  schema: './packages/core/src/drizzle/schema',
  out: './packages/core/src/drizzle/migrations',
  introspect: {
    casing: 'camel',
  },
});

package versions:

 β”œβ”€β”€ @aws-sdk/client-rds-data@3.677.0
β”‚ β”œβ”€β”€ @faker-js/faker@8.4.1
β”‚ β”œβ”€β”€ @types/lodash@4.14.202
β”‚ β”œβ”€β”€ @types/node@20.11.24
β”‚ β”œβ”€β”€ @types/pg@8.11.10 deduped
β”‚ β”œβ”€β”€ dayjs@1.11.10
β”‚ β”œβ”€β”€ drizzle-kit@0.26.2
β”‚ β”œβ”€β”€ drizzle-orm@0.35.3
β”‚ β”œβ”€β”€ graphql-tag@2.12.6
β”‚ β”œβ”€β”€ jsdom@24.1.0
β”‚ β”œβ”€β”€ lodash@4.17.21 deduped
β”‚ β”œβ”€β”€ pg@8.13.0
β”‚ β”œβ”€β”€ sst@2.41.4 deduped
β”‚ └── vitest@1.6.0

Let me know if there is anything else helpful I could provide, and thank you for your time.

Expected behavior

No response

Environment & setup

No response

eshrager commented 3 weeks ago

i have the same issue. upgraded to latest drizzle orm and kit and started getting this error when loading studio locally.

NikolaRusakov commented 2 weeks ago

Hello, the following patch file fixes the issue for me: https://gist.github.com/NikolaRusakov/88858b5b6a4e1585ca772f40f4e4d559#file-drizzle-orm-0-36-1-patch

the first if branch won't evaluate instanceof expression. I had to use constructor.name workaround, use it with caution.