tada5hi / typeorm-extension

This library provides utitlites to create & drop the database, seed the database and apply URL query parameter(s).
https://typeorm-extension.tada5hi.net
MIT License
211 stars 34 forks source link

Bug: typeorm-extension: seed:run Not Executing Specific Seed File (Version 3.5.0) #906

Closed anassarfraz closed 5 months ago

anassarfraz commented 6 months ago

Versions

Reproduction

I'm encountering an issue with typeorm-extension version 3.5.0 where the seed:run command doesn't seem to be executing the specified seed file, despite providing the correct path. Additional Details

Steps to reproduce

"seed:specific": ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run --dataSource typeorm-data-source.ts --name src/seeders/user.seeder.ts

this is my pacakge.json script cmd which i run for specific seed file

What is Expected?

The command should execute the seed logic defined in user.seeder.ts after successfully locating and loading the seed file.

What is actually happening?

api@0.0.1 seed:specific ts-node ./node_modules/typeorm-extension/bin/cli.cjs seed:run --dataSource typeorm-data-source.ts --name src/seeders/user.seeder.ts DataSource Directory: /home/anas/Documents/kwanso/boss-economics/backend > DataSource Name: typeorm-data-source.ts Seed Name: src/seeders/user.seeder.ts

seed:specific issue

The response only displays the data source name, directory, and file name, and doesn't actually trigger the execution of the seed logic within user.seeder.ts.

@tada5hi @guillaumedeslandes @ckaeslin @faloi @fossamagna

tada5hi commented 5 months ago

@anassarfraz can you provide a reproduction (git) repository ?

anassarfraz commented 5 months ago

@anassarfraz can you provide a reproduction (git) repository ?

yes sure i will create and share repository

anassarfraz commented 5 months ago

@tada5hi this code just related to problem i remove extra code from this repository.

https://github.com/anassarfraz/typeorm-extension-issue

just try to run npm run seed:specific for run the seed for specific file i mentioned in package.json file. actually it runs the commands in cli but not save the data in database. but if i run npm run seed:run it will save the data in database.

what actually i want to do? i am trying to run seed with this flag. --name seed:create & seed:run undefined Name (or relative path incl. name) of the seeder.

Thanks for your response.

tada5hi commented 5 months ago

You have to adjust the paths for seeds, migrations & factories in your typeorm-data-source.ts file: After the adjustment everything works fine :)

const options: DataSourceOptions & SeederOptions = {
  type: 'postgres', // IF you are using a different type of connector, please mention here explicitly.
  database: process.env.DATABASE_NAME || '',
  host: process.env.DATABASE_HOST || 'localhost',
  port: parseInt(process.env.DATABASE_PORT) || 5432,
  username: process.env.DATABASE_USERNAME,
  password: process.env.DATABASE_PASSWORD,
  migrationsRun: true,
  entities: ['src/**/**/*.entity.{ts,js}'],
  migrations: ['src/migrations/*{.ts,.js}'],
  seeds: ['src/seeders/*.seeder{.ts,.js}'],
};
tada5hi commented 5 months ago

@anassarfraz please close the issue if this solved your issue.

anassarfraz commented 5 months ago

i will check in a while then if resolved for me i will closed it.

thanks

tada5hi commented 5 months ago

your welcome!

anassarfraz commented 5 months ago

@tada5hi did you try to run code which i gave to you (https://github.com/anassarfraz/typeorm-extension-issue)

my typeorm-data-source.ts setting are fine and its paths for seed and migrations are fine , i am using swc compiler for compailing nestjs code.

my path for seeders and migrations are corrects thats why my code create table in migration and run all seeds on seed:run i just want to ask run seeder only for specific file not working ..

tada5hi commented 5 months ago

@tada5hi did you try to run code which i gave to you (https://github.com/anassarfraz/typeorm-extension-issue)

yes, without modifications, the run seed:specific does not work.

my typeorm-data-source.ts setting are fine and its paths for seed and migrations are fine , i am using swc compiler for compailing nestjs code.

When i modified them, everything worked

my path for seeders and migrations are corrects thats why my code create table in migration and run all seeds on seed:run i just want to ask run seeder only for specific file not working ..

The reason for this is, that none of the seed paths detected by the pattern 'dist/seeders/*.seeder{.ts,.js}' does match with the path src/seeders/user.seeder.ts