Saturday, 18 January 2020

Need help ordering seeders in adonisjs?

Currently, when you run 'adonis seed' it doesnt run seeds in orderly manner. Due to this many foreign key constraints are violated. To remedy this I tried automating its serialization using ace commands:'use strict'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) {this.success(`seed: ${seed}`)const exec =  execSync(`adonis seed --files ${seed} --force`, {stdio: 'inherit'})console.log(exec)    }  }}module.exports = SeedSync​Original code is copied from here: https://github.com/adonisjs/adonis-framework/issues/838​Any help will be much appreciated. Thank you for anyone who reads this.

Submitted January 19, 2020 at 05:11AM by ajirnanashak

No comments:

Post a Comment