Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seed dev database in Sails.js in a reproducible way

Tags:

sails.js

I'm looking for a best way to seed my development database in sails js.

In rails I would just use the seeds.rb file but even without that I could use a rake task.

With sails I am unsure of how I could do this outside of manually doing it with sails console.

Please note that solutions which add logic to config/models and the models themselves for production seeding are not what I am looking for. I don't want these records to exist in production.

like image 451
Andrew Avatar asked Dec 05 '25 14:12

Andrew


1 Answers

You can seed your database in the config/bootstrap.js file.


To seed it for a particular environment, what I usually do is:

// config/bootstrap.js
module.exports.bootstrap = function (cb) {

  if(process.env.NODE_ENV !== 'development')
    return cb();

  // Do whatever you want
  // And don't forget to...
  return cb();

};

And to drop the database each time during the Sails lifting:

// config/env/development.js
module.exports = {

  models: {
    migrate: 'drop'
  }

};
like image 97
Yann Bertrand Avatar answered Dec 07 '25 16:12

Yann Bertrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!