How to write database migration in sails.js application

I tried using the https://github.com/building5/sails-db-migrate module to create the migration, but it didn't work correctly. The table used to generate, but a few columns were missing. Is there a better way to create and run a migration? Sorry I'm new to sailing, recently switched from Php.

+3


source to share


3 answers


So it turned out that I was stupid to think that we need a module to write migration in sails. It turns out that when the sails are hoisted, the application automatically creates a table from the model's attributes.

But on trying, I realized that the waterline module that takes care of this is not creating foreign key constraints at the moment. They are still working on it.



If you are using nosql db then you can use the associations http://sailsjs.org/#!/documentation/concepts/ORM

+3


source


Time passes, but nothing changes with the sails. Beware of using it. If you are already in this trap - try https://www.npmjs.com/package/sails-migrations



+1


source


So people will get a clean and correct answer: ORM sails (waterline) already support automatic migration, you can change this in your config file (/config/models.js):

module.exports.models = {
   migrate: 'alter'
};

      

It takes the following parameters:

safe

- never automatic migration of my database. I will do it myself (manually)

alter

- automatic migration, but trying to keep existing data (experimental)

drop

- erase / delete ALL my data and rebuild the models every time I set sail

http://sailsjs.org/#!/documentation/concepts/ORM/model-settings.html

-1


source







All Articles