Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Losing dataSource on ResolveDataSource #3

Open
the1alt opened this issue Nov 15, 2022 · 3 comments
Open

Losing dataSource on ResolveDataSource #3

the1alt opened this issue Nov 15, 2022 · 3 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@the1alt
Copy link

the1alt commented Nov 15, 2022

Hi,

I'm trying to use this package, using rockets-starter to understand it.
Each time I try to seed datas, I have this error message :

Cannot read properties of undefined (reading 'name') at new DataSource (/Users/piman/Sites/manitude/node_modules/typeorm/data-source/DataSource.js:46:29) at Object.resolveDataSource (/Users/piman/Sites/manitude/node_modules/@concepta/typeorm-seeding/dist/utils/resolve-data-source.js:8:90)

It seems that the object dataSource from 'this.options' is not accessible inside of the resolveDataSource function, even through it exists in the get dataSource()'s function of the seeding-source.js;

Or maybe I'm not creating my seedingSource object correctly.

seeding.ts

import { ApiConfigService } from "./common/api-config/api.config.service";

const { config } = require('dotenv');
const { SeedingSource } = require('@concepta/typeorm-seeding');
const { AppSeeder } = require('./app.seeder');
const { default: DataSource } = require('./ormconfig');

config();

const options = {
  DataSource,
  seeders: [AppSeeder],
  defaultSeeders: [AppSeeder],
}

module.exports =  new SeedingSource(options);

ormconfig.ts

import { DataSource } from 'typeorm';
import { ormConfigFactory } from './common/api-config/typeorm.config';

const source = new DataSource({
  ...ormConfigFactory()
});

export default source;

typeorm.config.ts

import { DataSourceOptions } from 'typeorm';
import { registerAs } from '@nestjs/config';

export const ormConfigFactory = (): DataSourceOptions => {
  return {
    migrationsTableName: 'migrations',
    name: 'default',
    type: 'mysql',
    host: 'localhost',
    port: 3306,
    username: 'myname',
    password: 'mypassword',
    database: 'mydb',
    logging: false,
    synchronize: false,
    entities: ['src/endpoints/**/**.entity{.ts,.js}'],
    migrations: ['dist/migration/**/*{.ts,.js}'],
  };
};

export const ormConfig = registerAs('TYPEORM_MODULE_CONFIG', ormConfigFactory);

plackage.json scripts

"seed:config": "typeorm-seeding config -r ./dist -c src/seeding.js",
    "seed:run": "typeorm-seeding seed -r ./dist -c src/seeding.js"

image

image

@the1alt the1alt changed the title Losing options on ResolveDataSource Losing dataSource on ResolveDataSource Nov 15, 2022
@MrMaz MrMaz self-assigned this Dec 6, 2022
@MrMaz MrMaz added the help wanted Extra attention is needed label Dec 6, 2022
@MrMaz
Copy link

MrMaz commented Dec 6, 2022

I apologize for not responding, I was out on vacation and I am just catching up. Did you ever find the solution on your own, or do you still need help?

@the1alt
Copy link
Author

the1alt commented Dec 16, 2022

Hi, i switched to an older version of type-orm
If you find the solution it could be great

@MrMaz
Copy link

MrMaz commented Dec 16, 2022

@the1alt can you provide a repo that reproduces the issue? it may be as simple as configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants