Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: Undefined in DataSource variables #803

Closed
JMR-Mejia opened this issue Dec 14, 2023 · 1 comment · Fixed by #829
Closed

Bug: Undefined in DataSource variables #803

JMR-Mejia opened this issue Dec 14, 2023 · 1 comment · Fixed by #829

Comments

@JMR-Mejia
Copy link

Versions

  • Node: 18.17.1
  • OS: Linux 22.04 LTS

Reproduction

When the seed:run command is used as indicated in the documentation, it does not take the values ​​found in the data source file, leaving all fields as undefined or default

Steps to reproduce

Just creating a basic data source file

import { DataSource, DataSourceOptions } from 'typeorm';
import { config } from 'dotenv';
import { SeederOptions } from 'typeorm-extension';
import InitSeeder from './src/database/seeds/test/init.seeder';

config();

const options: DataSourceOptions & SeederOptions = {
  type: 'postgres',
  host: 'process.env.POSTGRES_HOST',
  port: 5432,
  database: 'trippster',
  username: 'postgres',
  password: 'password',
  seeds: [InitSeeder],
  ssl:
    process.env.NODE_ENV === 'production'
      ? { rejectUnauthorized: false }
      : false,
  synchronize: true,
  logging: true,
  entities: ['src/**/*.entity.ts'],
  migrations: ['src/database/migrations/*.ts'],
};

console.log(options);

const dataSource = new DataSource(options);

console.log(dataSource);

export { dataSource };

and using the command

"seed:run": "ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run"

What is Expected?

It is expected to connect to the db and load the seeds, but it gives me the following error

Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: client password must be a string

as if I had not provided the data

Debugging I found the error is in the part of the merge where the options supplied by the data source and the ones read by the env

image
image

attached images to show that the data arrives up to that point and then returns the datasource in the cli as if it were undefined

@tada5hi
Copy link
Owner

tada5hi commented Jan 11, 2024

mhh, that can only happen if you set env variables. But in general one should consider that when merging options, non-undefined values have priority.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants