feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Seeder support (feature request) #13

Closed MartinBucko closed 6 years ago

MartinBucko commented 6 years ago

Idea

It will be cool to have build in template generator for service data seeder build in. :) https://github.com/thosakwe/feathers-seeder

Steps to reproduce

New services generated seed feature.

Expected behavior

First install dependencies:

npm i feathers-seeder

It should configure app with seed config in app.js:

const seeder = require('./seeder')
 app.configure(seeder)

It should have (in root probably) seeder.js script:

const seeder = require('feathers-seeder')
const usersSeed = require('./services/users/users.seed')

function seederOptions(app) {
  let options = {
    // delete globally all before seed
    // delete: false,

    // disable globally
    disable: false,

    // here add services to seed
    services: [usersSeed(app)]
  }

  return seeder(options)
}

module.exports = seederOptions

It should generate script service/users.seed.js (example only):

module.exports = function userSeed(app) {
  return {
    count: 1,
    delete: true,
    path: 'users',
    template: {
      name: '{{name.firstName}}',
      surname: '{{name.lastName}}',
      email: '{{internet.email}}',
      language: 'en',
      roles: ['basic'],
      loginFrom: 'web',
      loggedInAt: new Date(),
      isTest: true
    }
  }
}

Actual behavior

(No seeder support.) But we have already great tools in our hands. Sure my examples are quick and dirty. It should be optimised.

Thank You :)

eddyystop commented 6 years ago

Seeding a realistic set of tables would require seeding foreign keys. This is the main impediment to including a seeder.

I am not aware of a seeder repo which has that capability. Do you have an alternative or thoughts on this?

MartinBucko commented 6 years ago

@eddyystop Its possible to use callback in seeder options. There are called after record was created. This is way how to deal with foreign keys. Check the callback example in configuration docs: https://github.com/thosakwe/feathers-seeder#configuration

MartinBucko commented 6 years ago

Actually use of callbacks is little bit tricky and there is also problem of unpredictable execution order of more seeders. executing order of service array #9

eddyystop commented 6 years ago

Thanks for this info. I am looking in an alternative direction.

eddyystop commented 6 years ago

generate fakes has been introduced (beta) in f+/cli v0.5.1 using generator v0.3.1. https://generator.feathers-plus.com/get-started/#generate-fakes