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

populateDb expects seed files that export a function, but knex seed files exports.seed #61

Open
calvinl opened this issue Apr 1, 2019 · 6 comments

Comments

@calvinl
Copy link

calvinl commented Apr 1, 2019

Hi,

Have been using this package for awhile but recently started using it for seed files.

I've noticed that populateDb looks for a glob pattern of files, requires those files, and then checks to see if the module is a function. However, when generating knex seed files, the templates look like:

exports.seed = async function() {
  // ..seed data here
}

Where the module being loaded in knex-db-manager is { seed: [AsyncFunction] }. Therefore seed files aren't loading properly.

I have a commit here that fixes this, along with a fix for the wrong populatePathPattern. Can you tell me if this is an appropriate fix or if I'm missing something here? I can open a PR if the former, as well as write a test case for it.

Thanks!

@calvinl
Copy link
Author

calvinl commented May 20, 2019

bump

@elhigu
Copy link

elhigu commented May 20, 2019

Sure, I will gladly merge PR if you like to fix that. That commit seems legit fix 👍

@elhigu
Copy link

elhigu commented May 20, 2019

even that it is kind of a bug fix I'll mark it as breaking change, since old seeds if someone has used them will not work anymore.

@calvinl
Copy link
Author

calvinl commented May 20, 2019

@elhigu breaking change sounds right by me. thanks again! Just opened a PR at #68

@tstechly
Copy link

I have a updated fix (with passing tests). I can create another PR, but was thinking about that breaking change comment.
What about adding a switch to config that would use one or that other method of loading the seed module?

@elhigu
Copy link

elhigu commented Apr 19, 2020

I have a updated fix (with passing tests). I can create another PR, but was thinking about that breaking change comment.
What about adding a switch to config that would use one or that other method of loading the seed module?

Actually I hate having any seed support in knex / knex-db-manager (IMO they are completely useless for any non-trivial app and in test suite it is easier to write just custom methods as a part of test setup containing DB population functionality). So whatever works for me 😅 One could even dynamically check if there is module.seed run it and if it is a plain function then run the plain function.

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

3 participants