kk415kk
kk415kk

Reputation: 1247

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?

Upvotes: 1

Views: 1106

Answers (1)

kk415kk
kk415kk

Reputation: 1247

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().

Upvotes: 1

Related Questions