9

In sails.js, how can we stop the automigration of the schema into the database. Sometimes,it gives error due to the migration. Is there a way that we can make the migration run only when the application is deployed?

Joe Hill
  • 333
  • 3
  • 12
Luja Shrestha
  • 2,727
  • 2
  • 23
  • 29

3 Answers3

7

You can also try something like this:

module.exports = {

  // migrate: 'alter', // adds and/or removes columns on changes to the schema 

  // migrate: 'drop', // drops all your tables and then re-creates them. All data is deleted.

  // migrate: 'safe', doesn't do anything on sails lift- for use in production.

  attributes: { /* ... */ }

};
mikermcneil
  • 11,141
  • 5
  • 43
  • 70
JohnGalt
  • 2,851
  • 2
  • 21
  • 29
  • @mikermcneil, I tried to use this but after few days my data has vanished somehow,, I do not know how, I use this command forever -w start -al /var/log/mylog.log --prod – Sahan May 02 '15 at 02:20
  • Any thoughts @mikermcneil,, – Sahan May 02 '15 at 02:20
  • 2
    @user3656084 if you use `migrate:safe`, you'll be good to go (also note that if you run your app with `NODE_ENV=production`, this will happen automatically) – mikermcneil May 05 '15 at 15:26
  • @mikermcneil Do you know the answer for this question please ? http://stackoverflow.com/questions/30007526/step-by-step-guide-to-using-a-migrating-tool-for-production-sailsjs-system – Sahan May 06 '15 at 01:09
4

We can achieve that by specifying the migrate property in the model. Its default value is alter which attempt to auto-migrate the schema on every alteration.

module.exports = {
  schema: true,
  migrate: 'safe',
  adapter: 'mysql',

  attributes: {}
}
Luja Shrestha
  • 2,727
  • 2
  • 23
  • 29
3

For all models you can change in confing/models.js

migrate: 'safe',