Code Monkey home page Code Monkey logo

Comments (4)

eikaramba avatar eikaramba commented on June 12, 2024 2

that is exactly what i thought. i really think forcing some kind of order would be good for real-world use cases. sure with a relational db you will always run into these problems sooner or later but even with somethink like mongoDb you will want to run your services in some order, otherwise errors might occur.

For now i have like 10 nested callbacks, running after each other. it works, but is not really nice. especially considering that each callback is called for every entity, so i have a check to only call the next seed, if the last entity is processed.

from feathers-seeder.

thosakwe avatar thosakwe commented on June 12, 2024

Hm, if you look at the code for this, the configurations are executed in whichever order forEach runs them, which I assume is the order you supply them in.

But if you need to seed services that depend on others, you should really include a callback in your configuration.

{
  path: 'users',
  callback(user, seed) {
    return seed({
      path: 'panels',
      template: {
        userId: user._id,
        foo: {
            bar: '{{internet.userName}}'
            baz: '{{name.lastName}}'
        }
      }
    });
  }
}

from feathers-seeder.

eikaramba avatar eikaramba commented on June 12, 2024

Sure i know, but the callbacks can get quite ugly, as in a relational database it might be that everything is kind of tangled with each other.

Back to the issue: The code indeed doesn't look wrong, however i can assure you that he is misteriously not performing each promise as in the order of the array in the config. Maybe because of delete:true?

here is the debug log:

Seeding app...
Params seeding 'panels': {}
Param randomize: true
Creating 1 instance(s)
Params seeding 'users': {}
Param randomize: true
Creating 1 instance(s)
Params seeding 'users': {}
Param randomize: true
Creating 1 instance(s)
Params seeding 'users': {}
Param randomize: true
Creating 1 instance(s)
Params seeding 'studies': {}
Param randomize: true
Creating 1 instance(s)
Running 5 seeder(s)...
.....
Executing (default): CREATE TABLE IF NOT EXISTS "panels" ("id"   SERIAL , "name" VARCHAR(255) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT now(), PRIMARY KEY ("id"));
Executing (default): DELETE FROM "studies" <-- Here he already changed the order of the execution
Executing (default): DELETE FROM "panels"
Executing (default): DELETE FROM "users"
Executing (default): DELETE FROM "users"
Executing (default): DELETE FROM "users"
Deleted from 'studies:' []
About to compile this template:
**here he shows the study fields (last promise, but is executed first) **

from feathers-seeder.

jamesholcomb avatar jamesholcomb commented on June 12, 2024

The code which calls create() uses Promise.all(), so there is no guarantee of order.

It could be refactored to use an array reducer and thus execute in sequence...or you could manage that in your code like this:

const Seeder = require('feathers-seeder/lib/seeder');
const seeder = new Seeder(app, opts);

await seeder.seed(usersConfig)
await seeder.seed(panelsConfig)
await seeder.seed(studiesConfig)
...

If you're not using async/await, seed() is then-able (it returns a Promise)

For deleting data, I find it better to control up front, before initiating seed()

from feathers-seeder.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.