Search code examples
node.jsmodelssails.jsseeding

SailsJS: Best way to seed initial users


What is the proper way to seed the database with an initial admin/root user in a User model in Sails if one does not exist upon launch?


Solution

  • Solution: I found the solution to this problem. Since models are created before bootstrap.js is run in the config folder, I can simply check if a User model with ID "root" already exists, and if not, use User.create() to create the user.

    Long story short, just create the user in config/bootstrap.js BEFORE the callback cb().