cleverbeagle / seeder Goto Github PK
View Code? Open in Web Editor NEWA database seeder for Meteor applications.
A database seeder for Meteor applications.
Is it already possible to attach multiple collections to the same user, something like :
(same as last example of documentation)
data(userId) {
return [documentsSeed(userId), tasksSeed(userId)];
},
or it is a new feature request ?
If you want to seed in staging mode, you add
environments: ['development', 'staging']
but if you deploy using mup (or galaxy), you need to explicitly add in you mup.js config file (with ROOT_URL and such)
NODE_ENV: 'staging',
Otherwise the condition won't match (default is production if not development)
environmentAllowed(environments) {
if (environments) return environments.indexOf(process.env.NODE_ENV) > -1;
return false;
}
Maybe a little warning in documentation might help.
When trying to seed dependant collections, it seems that the data
function field is never called, unless the collection is Meteor.users
.
Let's take the code from pup
and add a Videos
collection. The Videos
collection is seeded, but not the Documents
import Videos from '../../api/Videos/Videos'; // Videos collection
const documentsSeed = ...
seeder(Videos, {
environments: ['development', 'staging'],
wipe: true,
noLimit: true,
modelCount: 3,
model(index) {
console.log(`creating videos ${index + 1}`);
return {
title: `Title of video #${index + 1}`,
data(videoId) {
console.log('This is never called');
return documentSeed(videoId);
},
};
},
});
Every time my meteor server restarts (often), a batch of 100 test users are created. Ever time a user is created, I send out two emails: one welcome email and a verification email. Sending these emails is taxing on local development, not necessary for development purposes, and costs $ (I use SES).
Is there a way we can specify to not fire emails on these fake sign ups?
My application supports signing up via Facebook in addition to normal email and password.
Can this package support faking Facebook-based users?
Doing a deployment and the disallowed environment check is throwing an error that's crashing the container. Need to silently fail or just log a warning.
You can create a user with a username
property, but we don't check to see if the username already exists.
Right now this only checks the email address, but username should also be considered unique.
Here is solution to index.js
createUser(collection, user, iteration) {
const userToCreate = user;
/* // Error: if username is null finds first with null and isExistingUser has true
const isExistingUser = collection.findOne({
$or: [
{ 'emails.address': userToCreate.email },
{ username: userToCreate.username },
]
});
*/
let condition = [{ 'emails.address': userToCreate.email }];
if (userToCreate.username) {
condition.push({ username: userToCreate.username });
}
const isExistingUser = collection.findOne({$or: condition });
if (!isExistingUser) {
const roles = userToCreate.roles;
if (roles) delete userToCreate.roles;
const userId = Accounts.createUser(userToCreate);
if (roles && Roles !== 'undefined') Roles.addUsersToRoles(userId, roles);
if (userToCreate.data) this.seedDependent(userId, userToCreate.data, iteration);
}
}
Pass an array instead of a single object.
Hi, great work for this package.
Is it possible to add verbose mode so it would print the progress of the seeding in the server console ?
This is particularly useful for displaying information about which data is finally present in the database and displaying smooth error (or ignoring them on production for instance).
I think a verbose
boolean should be added to the seeder
object in order to enable/disable verbose mode. If enabled, it would print :
This could be improved for much more information about populated data, but I suppose this is enough for most usage and a good start ๐
I want to add a bunch of dependent data after users have been inserted. Right now the extra data
method requires you to return a function that specifies a single collection
name. But this doesn't work for complex systems that have dependent data that needs to go into multiple collections, simultaneously (i.e. if you follow someone, an insert needs to happen on both the Followers
and Followees
collections).
It would be great if data
did not require a return value, which would allow the developer to write any old javascript function containing their custom logic. I.e.
data(userId) {
createUserFollowships(userId);
},
Notice the omission of return
. The above code works functionally, however the Meteor console gets spammed with errors:
TypeError: Cannot read property 'collection' of undefined
W20170718-15:17:47.814(-4)? (STDERR) at Seeder.seedDependent (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:109:50)
W20170718-15:17:47.814(-4)? (STDERR) at Seeder.createUser (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:96:37)
W20170718-15:17:47.814(-4)? (STDERR) at Seeder.sow (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:64:20)
W20170718-15:17:47.814(-4)? (STDERR) at Seeder.seed (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:45:23)
W20170718-15:17:47.814(-4)? (STDERR) at new Seeder (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:26:12)
W20170718-15:17:47.815(-4)? (STDERR) at exports.default (/Users/jcursi/Sites/joncursi/redbird-web/node_modules/@cleverbeagle/seeder/index.js:117:10)
W20170718-15:17:47.815(-4)? (STDERR) at users.js (imports/startup/server/fixtures/users.js:18:7)
W20170718-15:17:47.815(-4)? (STDERR) at fileEvaluate (packages/modules-runtime.js:333:9)
W20170718-15:17:47.815(-4)? (STDERR) at require (packages/modules-runtime.js:228:16)
W20170718-15:17:47.815(-4)? (STDERR) at index.js (imports/startup/server/fixtures/index.js:3:1)
A lot has been learned about tests since this package was released. Would be good to improve tests and realign with new 2.0.0 features.
Bug in index.js
key: 'createData',
value: function createData(collection, value) {
//fixing bug - new var
var data = value.data;
///
var dataId = collection.insert(value);
//fixing bug value.data lost
//if (value.data) this.seedDependent(dataId, value.data);
if (data) this.seedDependent(dataId, data);
}
}
v1 of this package has worked well, but the internals are a bit confusing coming back to it. Need to do a refactor of the code to simplify it and make extension/maintenance a little easier.
Right now the seeder works well enough for seeding on startup, but it'd be nice if you could call it and get back data without hitting the DB. E.g., to generate seed data for tests.
Forgot about this problem from v1. Due to how the SimpleSchema package works (commonly used for defining schemas on MongoDB collections in Meteor), it scrubs any data that doesn't match the schema. dependentData
gets caught up in this. Need to cache dependentData
in a variable and remove it before passing a date item to a collection in case it's using SimpleSchema.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.