const { Command } = require('@adonisjs/ace')
const util = require('util')
const execSync = util.promisify(require('child_process').execSync)
const defaultSeedOrder = []
class SeedSync extends Command {
static get signature () {
return `seed:sync
{
order? : Comma separated of seeds
}`
}
static get description () {
return 'Seeds based on a list instead of running all seeds async.'
}
handle (args, options) {
let seedOrder;
if (args.order !== null) {
seedOrder = args.order.split(/=(.+)/)[1].split(',')
} else {
seedOrder = defaultSeedOrder
}
for (const seed of seedOrder) {
console.log(seed)
execSync(`adonis seed --files='${seed}'`, (e, stdout, stderr) => {
if (!stdout.includes('Seeded database in')) {
this.error(`${this.icon('error')} Error: `)
}
console.log(stdout)
})
}
}
}
module.exports = SeedSync
I want an ace command to run seed sequentially, I have copied this code from here: Link to the original code
But it doesnt seem to work at all for me.
Any help will be much appreciated, Thank you
The problem is with these 2 blocks.
This signature needs to be like this to work and get the order variable correctly:
static get signature () {
return `
seed:sync
{ --order=@value: Run only selected files }
`
}
AND
const exec = execSync(`adonis seed --files='${seed}' --force`, {stdio: 'inherit'})
Remove the commas on --files='${seed}'
so that it reads --files=${seed}
Because on the terminal, we call the command using adonis seed:sync --order=''
(this single comma is passed to adonis Seed.js and causes the error "Nothing to Seed")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.