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

Improve documentation for default seeder #75

Closed
lparolari opened this issue Feb 5, 2022 · 5 comments
Closed

Improve documentation for default seeder #75

lparolari opened this issue Feb 5, 2022 · 5 comments

Comments

@lparolari
Copy link

Hi! Thank you for the awesome work you do maintaining this library.

Please consider to mention in documentation that seeder classes should be exported without default export if the defaultSeeder configuration is set to the name of the seeder as you show in examples ("RootSeeder").

I just wasted one hour figuring out why my default seeder was not found. Maybe the solution was trivial, but not for me :)
Hope this may help other peoples.

Thank you.

@jorgebodega
Copy link
Owner

Yes, documentation is something that i have to improve on this library. Unfortunately, I don't have enough time to do, at least by the moment.

Sorry if you spent too many time trying to make that work, will be great to know what was the problem and add it to docs

@lparolari
Copy link
Author

No problem, it's my misunderstanding!

In the next days I'll try to open a PR, I'm glad to help :)

@lparolari
Copy link
Author

lparolari commented Feb 7, 2022

Just for information:

Problem

  1. create a seeder
// ./path/to/seeder/RootSeeder.ts

export default class RootSeeder extends Seeder {  // <-- note the keyword "default"
  async run(connection: Connection): Promise<void> {
    // ...
  }
}
  1. set the default seeder in config (in my case, ormconfig.json
{
  ...
  "seeders": ["./path/to/seeders/*.ts"],
  "defaultSeeder": "RootSeeder"
  ...
}

Error

✔ ORM Config loaded
✖ Could not import seeders!
Error importing seeders: Seeder RootSeeder does not exist
error Command failed with exit code 1.

Expected behavior

It finds the seeder RootSeeder and executes seeding.

Solutions

Solution 1

(Recommended, in my opinion)

Remove the default export from RootSeeder:

// ./path/to/seeder/RootSeeder.ts

export class RootSeeder extends Seeder {  // <-- "default" removed
  async run(connection: Connection): Promise<void> {
    // ...
  }
}

Solution 2

Update the ormconfig.json to

{
  ...
  "seeders": ["./path/to/seeders/*.ts"],
  "defaultSeeder": "default"
  ...
}

Please note that in this case, if you export more than one default seeder only the latest loaded will be executed.

@jorgebodega
Copy link
Owner

Mmm I will check this on this week or weekend, don't have too much time.

Thanks for your work!

@jorgebodega
Copy link
Owner

Sorry about the delay, just merge the PR

I will work on this next week, need to improve that functionality

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

No branches or pull requests

2 participants