Comments (4)
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.
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.
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.
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)
- Seeder works on "services" and not "models" HOT 2
- Reset autoincrement value for sequelize-adapter HOT 4
- 1.0.8 not working anymore HOT 1
- support faker locale option HOT 3
- How to handle several dependent seeds HOT 3
- Seeder not working with nuxt-js project HOT 4
- MIT License HOT 11
- enabling https HOT 3
- GeneralError: Cannot read property 'remove' of undefined HOT 1
- Getting dates in ISO format
- ResourceRequest timed out HOT 3
- Low Severe Vulnerabilities Found
- error: MethodNotAllowed: Can not remove multiple entries HOT 1
- Error on postinstall (Unknown plugin "add-module-exports") HOT 2
- question: creating users from predefined data HOT 1
- bug: number types in templates are empty HOT 1
- Import data 1:1 without randomization HOT 4
- Provide placeholder for Iterator number HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from feathers-seeder.