I am using knex for seeding and I have a folder called development where I have all the seeds files.
What I would want is: How to seed single file.
The command I am using is: knex seed:run --env=development But this command is to seed all the files and I get duplicate rows on db.
Suppose I have created seed files yesterday, and I seed them, today I want to add another seed file, which I only want to seed this file, not the files from yesterday.
An example from Laravel is: php artisan db:seed --class=ProductTableSeeder
Thanks
For those of you checking this in 2019+
According to the knex documentation
To run a specific seed file, execute:
$ knex seed:run --specific=seed-filename.js
Don't work: knex seed:run --specific=seed-filename.js
const file_name = path.basename(__filename)
const seedIsExist = await knex('knex_seeds_lock').where({ file_name }).first()
if (seedIsExist) {
return
}
await knex('knex_seeds_lock').insert({ file_name })
As a result, in the database you will get all the seed that you already ran earlier
Just move your scripts to another folder except the desired script, run the seed and copy the scripts back.
The seed API only has two commands, make and run. This is from the docs.
runknex.seed.run([config])
Runs all seed files for the current environment.
So all scripts will be executed on each run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With